Multiple choice

Consider the following code: If(num<=0) If(num<0) System.out.println(“Number is negative”) Else System.out.ptintln(“Number is positive”); If num=0, then output will become

  1. 0

  2. negative

  3. positive

  4. none of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The code provided is: If(num<=0) { If(num<0) print(negative) Else print(positive) }. If num is 0, the first condition (0<=0) is true. The inner condition (0<0) is false, so the else block executes, printing 'positive'.