Java Code
public class PrimeNumber {
public static void main(String[] args) {
int num = 13;
// A prime number is greater than 1 and has no divisors other than 1 and itself
boolean isPrime = true;
if (num <= 1) {
isPrime = false;
} else {
// Loop starts from 2 and checks till num/2
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
isPrime = false;
break; // No need to check further
}
}
}
if (isPrime) {
System.out.println(num + " is a prime number.");
} else {
System.out.println(num + " is not a prime number.");
}
}
}
Output
13 is a prime number.