find the output of the following program segment
for(int x=15;x>1;x-=2)
{
if(x>10)
System.out.println(++x);
else
System.out.println(--x);
}
Answers
Answered by
0
16
15
14
13
12
9
6
3
when x= 15 , 15>1 , 15>10 is true so ++x=16
now , x-=2 is 14 , 14>1 , 14 > 10 is true so ++x= 15
this continues until value of x becomes less than 10
after that the else block gets executed until the condition x>1 becomes false.
Similar questions
Biology,
2 months ago
English,
2 months ago
Math,
2 months ago
Accountancy,
4 months ago
Physics,
10 months ago
Physics,
10 months ago
Social Sciences,
10 months ago