I am trying to find the Prime Numbers between 1 and 100 using nested Loops but I am getting weird results.
I think I have a problem with my code but I can't figure out where exactly, can someone help me ?
The first loop that I made will count the numbers from 2 to 100 (i) the second one will count the numbers from 2 to i-1 (j) so when you divide i%j != 0 it should give you the Prime numbers am I right ? thanks a lot for your help
public static void main (String []args){
for(int i = 2; i<=100 ; i++)
{
for(int j = 2 ; j < i-1 ; j++ )
{
if (i%j != 0)
{
System.out.println(i );
}
}
}
}