//write a program to check number is prime or not?
public class PrimeNumber {
public static void main(String[] args) {
PrimeNumber.prime(31);
}
public static void prime(int n)
{
for(int i=2;i<n;i++)
{
if(n%i==0)
{
System.out.println("Number is not a prime number");
return;
}
}
System.out.println("Number is Prime");
}
}
o/p:-
Number is Prime
public class PrimeNumber {
public static void main(String[] args) {
PrimeNumber.prime(31);
}
public static void prime(int n)
{
for(int i=2;i<n;i++)
{
if(n%i==0)
{
System.out.println("Number is not a prime number");
return;
}
}
System.out.println("Number is Prime");
}
}
o/p:-
Number is Prime
No comments:
Post a Comment