Home » JAVA Programming » Decision Making » Question
  1. What would be the output of the following codesnippet if variable p=20?

    public class Result
    {
    public static void main(String args[])
    {
    int p=20;
    if(p<=0)
    {
    if(p==0)
    {
    System.out.println("5 ");
    }
    else
    {
    System.out.println("10 ");
    }
    }
    System.out.println("15 ");
    }
    }
    1. 10
    2. 50
    3. 15
    4. 20
    5. 30
Correct Option: C

Since the first if condition is not met, control would not go inside if statement and hence only statement after the entire if block will be executed.



Your comments will be displayed only after manual approval.