Write a java program to check no is prime or not.
import java.util.Scanner;
class prime
{
public static void main(String args[])
{
System.out.println("Enter number");
Scanner sd =new Scanner(System.in);
int i=sd.nextInt();
int j=2,l=0,k=0;
while(j<(i/2))
{
k=i%j;
if(k==0)
{
l++;
}
j++;
}
if(l>1)
System.out.println("Not prime no=" + i);
else
System.out.println("prime no=" + i );
}
}
No comments:
Post a Comment