The Java program takes a user input number and checks whether it is a prime number or not.
import java.util.Scanner; public class prime { //Write a program to check the given number is prime or not. public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter The Number : "); int n = in.nextInt(); int f = 0; for (int i = 1; i <= n; i++) { if (n % i == 0) { f++; } } if (f == 2) { System.out.println(n + " is a Prime Number"); } else { System.out.println(n + " is not a Prime Number"); } } }
Enter The Number : 17 17 is a Prime Number
Enter The Number : 10 10 is not a Prime NumberTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions