What will be the output of the program? class test { public static void main(string [] args) { int x= 0; int y= 0; for (int z = 0; z < 5; z++) { if (( ++x > 2 ) || (++y > 2)) { x++; } } system.out.println(x + " " + y); } }?
Answers
Answered by
6
✪Hey There✪
The OutPut Will be 6, 3
In the first iteration, it goes in to the "if" and first increments "x" and checks the condition.. it fails. then it wont go for the next condition to check(we used "&&" so both the conditions should be true to enter into the "if" block.
next iteration will also fails (Coz 2>2 fails)
In third iteration "x" will be 3. but "Y" incremented by 1 so "y=1"(again fails 1>2)
In fourth iteration "x" will be 4 but still the second condition is not satisfied "y=2" only (2>2 fails).
In fifth iteration "x" will be 5 and "y" will be 3, condition true so enters into "if" and increments x by 1. so x=6.(6>2 and 3>2)
finally x=6 and y=3
Hope It Helps.☺️
The OutPut Will be 6, 3
In the first iteration, it goes in to the "if" and first increments "x" and checks the condition.. it fails. then it wont go for the next condition to check(we used "&&" so both the conditions should be true to enter into the "if" block.
next iteration will also fails (Coz 2>2 fails)
In third iteration "x" will be 3. but "Y" incremented by 1 so "y=1"(again fails 1>2)
In fourth iteration "x" will be 4 but still the second condition is not satisfied "y=2" only (2>2 fails).
In fifth iteration "x" will be 5 and "y" will be 3, condition true so enters into "if" and increments x by 1. so x=6.(6>2 and 3>2)
finally x=6 and y=3
Hope It Helps.☺️
Answered by
1
Explanation:
✪Hey There✪
In fifth iteration "x" will be 5 and "y" will be 3, condition true so enters into "if" and increments x by 1. so x=6.(6>2 and 3>2)
finally x=6 and y=3
Hope It Helps.☺️
Similar questions
Science,
8 months ago
English,
8 months ago
Economy,
8 months ago
Business Studies,
1 year ago
Business Studies,
1 year ago
Chemistry,
1 year ago