package pl.codegym.task.task04.task0438;
/*
Rysowanie linii
*/
public class Solution {
public static void main(String[] args) throws Exception {
for (int i = 1; i <=10; i++){
if (i == 1){
for (int j = 1; j <=10; j++){
System.out.print ("8");
}
}
else
System.out.println ("8");
}
}
}
dlaczego "for (int i = 1; i <=10; i++)" w tym przypadku wyswieta 8 znakow zamiast 9-ciu?
Dyskutowane
Komentarze (2)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Guadalupe Gagnon
2 marca 2020, 20:48
It is outputting 10 times according to how the it is programmed:
1 2 3 4 5 6 7 8 9 10 = j
i = 1 > 8 8 8 8 8 8 8 8 8 8 (i = 2) > 8
i = 3 > 8
i = 4 > 8
i = 5 > 8
i = 6 > 8
i = 7 > 8
i = 8 > 8
i = 9 > 8
i = 10 > 8
Here is a graph of what is happening. When i = 1 the loop that works on j activates which outputs ten "8"s on the same line. When i = 2, the next eight is placed right at the end of that line because no new line characters are given between the last 8 of the j loop and the next 8 from the i loop.
0
Hubert
3 marca 2020, 12:02
that was helpful, thanks :)
0