Java Program on Prime Number
- Categories Java
Accept a number from user and print if given number is prime number or not?
import java.util.Scanner; public class primeNumber { public static void main(String[] args)
{
System.out.println("Enter the number:");
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("Yes");
else
System.out.println("No");
}
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021