Write a program in Java to check weather a given number is prime
or not.
Program:
class
Sk02
{
public static void main(String args[])
{
short n= 5;
int c=0;
for(int
i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
{
System.out.println("The number
"+n+" is Prime Number");
}
else
System.out.printf("The number is not
Prime");
}
}
Compile:
D:\>javac
Sk02.java
Run:
D:\>java
Sk02
Output:
The
number 5 is Prime Number
0 Comments