3
I’m studying repetition structure in Java here. And I came across the will to do the following:
public class Teste {
public static void main(String[] args) throws IOException {
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
System.out.println("Linha: " + j);
}
System.out.println(" Registro: " + i);
}
}
}
The exit from this stretch is:
Linha: 1
Linha: 2
Registro: 1
Linha: 1
Linha: 2
Registro: 2
And the desired exit would be:
Linha: 1
Linha: 2
Registro: 1
Linha: 3
Linha: 4
Registro: 2
That is, that in the second turn of the first loop the j was not zeroed, thus generating Line 3 and Line 4 for the second record.
How do I do that?
Just change the first one to
for (int i = 1; i <= 4; i++)
– Jéf Bueno