212k views
4 votes
What is the output of the following code snippet? int num = 100; if (num < 100) { if (num < 50) { num = num - 5; } else { num = num – 10; } } else { if (num > 150) { num = num + 5; } else { num = num + 10; } } System.out.println(num);

User Antia
by
5.8k points

2 Answers

3 votes

Cde

Step-by-step explanation:

Because if you look at abcdefghi, In programming you start with 0. So it would be a:0 b:1 c:2 d:3 e:4 f:5 g:6 h:7 i:8. So if you say 2:5, it would be from c to e. Because in programming you dont count the last letter which is 5 you use the letter right before 5 to end it.

User Adroit
by
5.0k points
2 votes

Answer:

110

Step-by-step explanation:

  1. A little correction is made to the code snippet (num = num – 10;) changed to (num -=10;)
  2. The code snippet uses if and else to check the value of num (Initially set to 100)
  3. The first test if (num < 100) is false. So it jumbs to the else block
  4. The second test if (num > 150) is also false. So it moves to the last else block which is else { num = num + 10; This adds 10 to the initial value of num which was 100. As such 110 is printed out.
User Mizbah Ahsan
by
5.2k points