Computer Science, asked by MAKTVDTO, 1 year ago

Write a program to accept a number and check whether its a prime number or not.Prime numbers have only 2 divisors so count the divisors and after the loop, check whether it is two or not.

Answers

Answered by Anonymous
3

Public class prime
{
Public static void main (String arg[])
{
Scanner in =New scanner (System.in)
int I, n, c=0
System. Out. Println ("enter number")
n=in.nextInt()
for(i=1 .i<=10.i++)
{
If (n%i==0)
c=c+1
If(c==2)
System .out. println ("it is prime number ")
else
System .out. println("not an prime number ")
}
}
}



Anonymous: Is it right???
MAKTVDTO: Thank you....its exactly what i wanted. with the scanner class abd and all. Thankyou soo much!!!
Similar questions