WAP to check if a given number is prime or not.

import java.util.*; class T11 { public static void main(String[] args) { int i, n, c = 0; Scanner sc = new Scanner(System.in); System.out.print("Enter a number to find if it is prime or not: "); n = sc.nextInt(); for (i = 1; i <= n; i++) { if (n % i == 0) { c++; } } if (c == 2) { System.out.println(n + " is a Prime Number."); } else { System.out.println(n + " is not a Prime Number."); } } } Copy Code
Expected Output:
Input:
Number: 5

Output:
5 is a Prime Number.