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
This blog needs a youtube channel, lol…