Computer Science, asked by rupalijais4103, 4 months ago

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 ranuatri08
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