I cannot find the answer/help via google show I'll ask help here.
For some reason the for loop does not work anymore. For example, with this code (answer of level 7, lesson 9):
BufferedReader bis = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 5; i++) {
String s = bis.readLine();
list.add(s);
}
list.remove(2);
Collections.reverse(list);
for (String s : list) {
System.out.println(s);
}
it only prints out the content at index 0 (first in list), while it should print the whole list in reverse.
So, my for loops are not working anymore. What could this be?
Edit: i've checked the code in an online java compiler to and there it works properly
Intellij: for statement do not work anymore
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
John Squirrels Website Admin at CodeGym
10 January 2021, 13:55
Maybe something wrong with IntelliJ IDEA settings. Try re-installing it.
0
Andrej
6 January 2021, 12:41
Seems kinda strange to me, I can't see a problem in there. Code looks alright. Maybe you should try to run it in debug mode and check the contents of list at each iteration, or you can just print it every time to see what's happening in there.
0