Input:20
Output:0 is not a Prime
1 is not a prime
2 is a prime
3 is a prime
4 is not a prime
5 is a prime
20 is not a prime(upto number 20)
My Class
public class Prime{
public static void main(String[] args){
int number=20;
int p;
for(int i=2;i<number;i++){
p=0;
for(int j=2;j<i;j++){
if(i%j==0){
p=1;
}
}
if(p==0){
System.out.println(i+" "+"Is Prime");
}
}
}
}
In the above program I printed the prime numbers,How to print both prime and non prime numbers in it?Thanks in advance! check it from 0 is not a Prime, 1 is not a prime, 2 is a prime, 3 is a prime, 4 is not a prime, 5 is a prime, 7 is a prime, 8 is not a prime ,continues upto n given