Java program to check whether given number is prime number or not
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
int num,i,count=0;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
num=Integer.parseInt(br.readLine());
for(i=1;i<=num;i++){
if(num%i==0)
count++;
}
if(count==2)
System.out.println(num+" is a prime number");
else
System.out.println(num+"is not a prime number");
}
1 comment:
thnx....
Post a Comment