Composite Number
- Categories Java
Find if number is a Composite number . its is a number which has more that one factor(excl. 1,n). e.g. 8=2,4=2 factors.
import java.util.Scanner;
public class CompositeNum
{
public static void main(String[] args)
{
System.out.println("Enter the number:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count = 0;
for(int i = 1; i <= n; i++) {
if (n % i == 0)
count++;
}
if (count >3)
System.out.println("Yes");
else
System.out.println("No");
}
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021