java program for checking prime number

admin February 18, 2014 0 Comments

checking prime number

import java.util.Scanner ;
class CheckPrime
{
public static void main ( String s[] )
{
System.out.println ( " Enter a number: ");

Scanner value = new Scanner ( System.in );
int number = value.nextInt ( );
int flag =0;
int c = (int) Math.sqrt( number );

 

 

 
for ( int i = 2 ; i <=c ; i++ )
{
if ( (number % i ) == 0 )
{

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

flag =1 ; break ; }

}

if (flag == 0 )

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

Leave a Reply