Prime Number Program in Java | write a program to print Prime Number Program in Java.

Prime Number Program in Java
Sirf Padhai

write a program to print Prime Number Program in Java.

import java.util.Scanner;

public class Prime
{
public static void main(String args[])
{
int num,i,count=0;
System.out.println("Enter a number: ");
Scanner enter = new Scanner(System.in);
num = enter.nextInt();
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1){
System.out.println(num + " is a prime number");
}
else{
System.out.println(num + " is not a prime number");
}
}
}

Output….

Enter a number:
9
9 is a prime number

Previous articleFibonacci series program in java
Next articlePalindrome Program in Java in Hindi

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here