How to account for non-prime numbers 0 and 1 in java?
- by shady
I'm not sure if this is the right place to be asking this, but I've been searching for a solution for this on my own for quite some time, so hopefully I've come to the right place.
When calculating prime numbers, the starting number that each number has to be divisible by is 2 to be a non-prime number. In my java program, I want to include all the non-prime numbers in the range from 0 to a certain number, so how do I include 0 and 1? Should I just have separate if and else-if statements for 0 and 1 that state that they are not prime numbers? I think that maybe 0 and 1 should be included in the java for loop, but I don't know how to go about doing that.
for (int i = 2; i < num; i++){
if (num % i == 0){
System.out.println(i + " is not a prime number. ");
}
else{
System.out.println(i + " is a prime number. ");
}
}