java - Why can't I loop through the ArrayList -


i wanted make simple prime number printer in java, , last loop giving me error.

import java.util.arraylist;  public class main {  	public static void main(string[] args) {  		arraylist<integer> primenumbers = new arraylist<integer>();  		primenumbers.add(1);  			for (int = 2; true; i++){  				for(int j = 2; j <= i; j++){  					double = i/j;  					if(a % 1 == 0 && != j) primenumbers.add(i);  				}  			}  			for (int value : primenumbers) {  			    system.out.println(value);  			}  	}  }

why happening?

because outer for loop infinite (that last loop unreachable). change this

for (int = 2; true; i++) { // <-- infinite loop 

to like

for (int = 2; < 1000; i++) { // 2 1000. 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -