check whether the number provided by the user prime or not in java-porgrammingraja

 Aim:- Write a program to check whether the number provided by the user is prime or not.


Software used:- Notepad, Command prompt


Program coding:-

class prime

{

public static void main(String args[])

{

int i, n=0;

n = Integer.parseInt(args[0]);

for(i=2;i<n;i++)

if(n%i==0)

break;

if(i==n)

System.out.println("The number " + n + " is prime");

else

System.out.println("The number " + n + " is not prime");

}

}

Output: 




Post a Comment

0 Comments