Friday, 20 December 2019

Java Program to check whether a no. is composite or not

//Composite Number checker.
import java.util.*;
class Composite
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,n,p,q,k;
do
{
System.out.println("Enter the no. zero to quit");
n=sc.nextInt();
if(n!=0)
{
System.out.println("Enter no.");
}
else
{
System.out.println("End of the process");
System.exit(0);
}
m=sc.nextInt();
k=m;
p=2;
q=0;
do
{
if(m%p==0)
q=q+1;
p=p+1;
}while(p!=m);
if(q>=1)
System.out.println("Composite No.");
else
System.out.println("Not Composite");
}while(n!=0);
}
}

No comments:

Post a Comment

Convey your thoughts to authors.