Find the output of the following java program:
for(a=2,b=100;a<=21;a+=3,b=-2)
System.out.println(a+","b);
plzz explain also......................i need it real fast
Answers
Answered by
1
Given:
for(a = 2, b = 100, a < = 21; a+ = 3; b = -2)
Step 1:
a = 2, b = 100.
System.out.println("a+","+b);
Output:
2,100
Step 2:
2 < 21{true}
a+=3 ⇒ a = 2 + 3 = 5
b=-2;
System.out. println("a+","+b)
Output:
5, -2
Step 3:
5 <= 21 {true}
a+= 3 ⇒ a = a + 3 = 8.
b=-2
System.out.println("a+","+b)
Output:
8,-2
Step 4:
8<21 {True}
a+=3 ⇒ a = 8 + 3 = 11
b = -2.
System.out.println("a+","+b);
Output:
11,-2
Step 5:
11 < 21{True}
a+=3 ⇒ a = 11 + 3 = 14
b = -2.
System.out.println("a+","+b);
Output:
14, -2
Step 6:
14 < 21{True}
a+=3 ⇒ a = 14 + 3 = 17
b = -2.
System.out.println("a+","+b);
Output:
17,-2
Step 7:
17 < 21
a+=3 ⇒ a = 17 + 3 = 20
b = -2.
System.out.println("a+","+b);
Output:
20,-2
Step 8:
20 < 21 {Wont satisfy, because we get 23 < 21..Condition false}
Output:
2,100
5,-2
8,-2
11,-2
14,-2
17,-2
20,-2
Similar questions