Check number is PRIME Or Not
import java.util.*;
public class javabasics{
public static void main(String args[]){
Scanner s =new Scanner(System.in);
boolean k=true;
System.out.println("Enter The Number");
int n=s.nextInt();
if(n<2){
System.out.println("Not a prime Number");
}
else{
for(int i=2;i<Math.sqrt(n);i++){
if(n%i==0){
k=false;
break;
}
}
if(k==false){
System.out.println("Nor Prime Number");
}
else{
System.out.println("prime number");
}
}
}
}
Comments
Post a Comment