0

Friends i want know how the output is come 6

public class Program { public static void main(String[] args) { int m,n=0; for(m=1; m<=4; m++){ n+=m; n--; } System.out.println(n); } } /* Output 6 */ Please understand me briefly...

14th Jul 2020, 11:13 AM
born2code
born2code - avatar
4 odpowiedzi
+ 3
Normally 1+2+3+4 but in each of 4 loops n-- So 10 -4=6
14th Jul 2020, 11:17 AM
Oma Falk
Oma Falk - avatar
+ 1
(n+m)-1=n (equal to). 0+1 -1 =0 0+2 -1 =1 1+3 -1 =3 3+4 -1 =6 @Kiibo since n-- is a separate statement. (post or pre, no difference, not effect in result.) @Oma Falk teacher is fast, applied farmula some of sequestial numbers - iterations just.
14th Jul 2020, 1:22 PM
Jayakrishna 🇮🇳