Write a program to check if a number is prime.
import java.util.Scanner;
public class star {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int count=0;
for (int i=1;i<=n;i++)
{
if (n%i==0)
count++;
}
if (count==2)
System.out.println("Prime");
else
System.out.println("Not Prime");
}
}
🔗Reference: stackoverflow.com
🔗Source: Java Interview Questions and Answers