Wednesday, January 16, 2008

Prime Number

Here is a Program to find a number is prime or not

import java.io.*;
class prime
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any no,");
int a = Integer.parseInt(br.readLine());
int fac=0;
for(int i =2;i{
if(a%i==0)
fac=1;
break;
}
if(fac==0)
System.out.println("Prime Number");
else
System.out.println("Not Prime Number");
}
}

2 comments:

Unknown said...

why had you had taken fac = 1?
tell please

Snaazze said...

instead of doing fac++ he has taken fac =1...