- 1
Why does this code output 8?
Can u please explain how does this code output 8 i dont get it int x = 2; for (int i=1; i <=3; i++) { x += i; } System.out.print(x); https://code.sololearn.com/cLqlXMbQEIU7/?ref=app
13 ответов
+ 6
2 + 1 = 3
3 + 2 = 5
5 + 3 = 8
That is how you get x = 8
+ 1
Elsa now i got it thnx so much u helped me alot 💜
+ 1
int x = 2;
int i=1;
i <= 3 // 1 <= 3 true
x = x + i; // 2 + 1 = 3
i = i + 1 // 1 + 1 = 2
i <= 3 // 2 <= 3 true
x = x + i; // 3 + 2 = 5
i = i + 1 // 2 + 1 = 3
i <= 3 // 3 <= 3 true
x = x + i; // 5 + 3 = 8
i = i + 1 // 3 + 1 = 4
i <= 3 // 4 <= 3 false
.print(x) // 8
0
Brain & Bones i dont understand why did u combine 2+1 and then 3+2 and then 5+3:---:
0
Islam Puth I wrote this code especially for you to clearly demonstrate how the "For" loop works:
https://code.sololearn.com/cA9tGLDoM1Tf/?ref=app
0
2+1=3
3+2=5
5+3=8
I is being added to x Everytime the when the code is run.
0
Can anyone explain what is href
0
href is used in html . In this attribute we paste our link for the element.
0
https://code.sololearn.com/WtF5i0C78QPr/?ref=app
Please see this once
- 1
At start , x = 2
Inside for loop:
i = 1<=3 (condition satisfied)=> x = 2+1=3 [x = x +i]
i = 2<=3 (satisfied)=> x = 3+2 =5
i = 3 <=3(satisfied)=> x = 5+3=8
Hope this helps u!
- 1
Thanks for answer
- 1
Why is src used , what's the meaning of src in html
- 1
src is used for the path of a file you use in html.