JAVA Program to determine whether a number is prime or not
WAP to determine whether an entered number is prime or not.
import java.util.Scanner; class Prime_number
{ public static void main(String[] args)
{ Scanner s = new Scanner( System.in ); System.out.print( "Enter the number : " ); int num = s.nextInt(); int i; for (i=2; i < num ;i++ )
{ int n = num%i; if (n==0)
{ System.out.println("not Prime!"); break; } } if(i == num)
{ System.out.println("Prime number!"); } } }
0 comments:
Post a Comment