0
¿Por qué este resultado?
public class Program { public static void main(String[] args) { int m=10, n=15; for(int i=1;i<=10;i++) m++; n++; System.out.println(m +""+n); } } //2016
7 Antworten
+ 4
when you leave out the curly brackets, only the 1st statement is considered by the loop.
+ 3
After the loop, m = 20 and n = 16.
+ 3
m++ means m = m +1, 10 times
n++ means n = n +1, but it's not inside of the loop, so 16
+ 2
m++ means m = m +1, 10 times
n++ means n = n +1, BUT IT'S NOT INSIDE OF THE LOOP, so 16
+ 2
Ok. Now i got it. Thanks for your help
0
Right but Why m increases 10 and n 1?
0
I just understand that. n++ means the same, so Why n increases only once?