This is my code:
import java.util.List;
import java.util.ArrayList;
public static void main(String[] args){
List<Integer> possible = new ArrayList<Integer>();
for(int i=0; i<1000000; i++){
possible.add(i);
}
for(int i: possible){
System.out.println(i);
}
}
I expected the output to print values from 0 to 999,999 with spaces in between. However, my output is:
208
850209
850210
850211... all the way to 999999
Why is my for loop skipping hundreds of thousands of values? I tried replacing int with long
and double
. Both skip values when running. Any help? I am just trying to create an ArrayList
of values from 0 to 999,999.