Computer Science, asked by shashwatbhai6, 5 months ago

write a program to input a number whelther it is a prime number or not in kaba

Answers

Answered by kamalrajatjoshi94
1

Answer:

import java.io.*;

public class Prime

{

public static void main(String args[])throws IOException

{

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

int num,a,c=0;

System.out.println("Enter the number");

num=Integer.parseInt(in.readLine());

for(a=1;a<=num;a++)

{

if(num%a==0)

c=c+1;

}

if(c==2)

System.out.println("It is a prime number");

else

System.out.println("It is not a prime number");

}

}

Similar questions