Hello. In this task, I noticed that the loop when I write:
int a = Integer.parseInt(reader.readLine());
for (int i = a ; 0 < i ; i--)
lista.add(Integer.parseInt(reader.readLine()));
The loop begins to retrieve an infinite number of characters. But when I write:
int a = Integer.parseInt(reader.readLine());
for (int i = 0; i < a ; i++)
lista.add(Integer.parseInt(reader.readLine()));
Everything works fine. I conclude that “ i “ in the For loop cannot be a value of another variable. Am I right?
Question about For
Dyskutowane
Komentarze (4)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Bob
5 lipca 2022, 08:33
in your first loop , this loop will continue when 0 < a,and i-- didnt change the value of a,so a will always bigger than zero,thats why the loop didnt stop.
sry for my bad English ahh
+1
Bob
5 lipca 2022, 08:34
the right one is " for(int i = a ; i > 0 ; i--) "
0
Mateusz
5 lipca 2022, 18:00
I made a mistake in describing the task. Please read it again
0
Bob
6 lipca 2022, 01:04
pls show me the whole code ,i dont know what a is
0