Hello , am new here and i need some help in finding prime numbers.....I actually wrote this code below and it compiles but it repeats sequence with some numbers or most, plus if you run it you will see that the prime numbers are printed as prime numbers only but repeated ...but if you notice the numbers that are not prime, it actually prints the numbers not to be prime and then prints them to be prime and then again not prime. Again it runs too many times for all the numbers. Can someone please help me see whats wrong with the code....thanks
public class Prime {
/**
* @param args
*/
public static void main(String[] args) {
int i,i2;
for ( i=1;i<=40;i++){
for(i2=1;i2<i;i2++){
if(i%i2==0 & i2!=1){
System.out.println(i+"is not prime\n");}
if(i%i2!=0){
System.out.println(i+"is a prime number\n");}
}
}
}
}