Java
import java.util.Scanner;
public class Main {
private static boolean isComposite(int n) {
if (n <= 3) return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return true;
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
if (isComposite(n)) {
System.out.println(n + " is Composite");
} else {
System.out.println(n + " is not Composite");
}
sc.close();
}
}Output
Enter a number: 12 12 is Composite
Composite numbers have at least one divisor other than 1 and themselves; we search for such a divisor.