which number is prime number code example
Example 1: prime number
a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11)
suppose a number 'n' it can be divided by if '1' and only by itself then it can be a prime number
Example 2: prime number
public class Prime {
public static void main(String[] args) {
int num = 29;
boolean flag = false;
for(int i = 2; i <= num/2; ++i){
if(num % i == 0){
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}}