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

16th Oct 2024, 4:21 PM
Luis
7 Respostas
+ 4
when you leave out the curly brackets, only the 1st statement is considered by the loop.
16th Oct 2024, 6:18 PM
Lisa
Lisa - avatar
+ 3
After the loop, m = 20 and n = 16.
16th Oct 2024, 4:22 PM
Lisa
Lisa - avatar
+ 3
m++ means m = m +1, 10 times n++ means n = n +1, but it's not inside of the loop, so 16
16th Oct 2024, 6:12 PM
Lisa
Lisa - avatar
+ 2
m++ means m = m +1, 10 times n++ means n = n +1, BUT IT'S NOT INSIDE OF THE LOOP, so 16
16th Oct 2024, 6:16 PM
Lisa
Lisa - avatar
+ 2
Ok. Now i got it. Thanks for your help
16th Oct 2024, 6:33 PM
Luis
0
Right but Why m increases 10 and n 1?
16th Oct 2024, 6:08 PM
Luis
0
I just understand that. n++ means the same, so Why n increases only once?
16th Oct 2024, 6:14 PM
Luis