Menu
Topics Index
...
`

Print PassFail Result - Java Example Program


Print PassFail Result
class PrintPassFail
{
    public static void main(String arg[])
    {
        int marks = 62;
        if(marks > 35)            // LINE A
        {
            System.out.println("Pass");     // LINE B
        }
        else
        {
            System.out.println("Fail");     // LINE C
        }
    
    }
}
OUTPUT

Pass

DESCRIPTION

Here marks are initialized to 62. Then the condition marks > 35 will become true, so LINE B is executed which prints Pass. If the marks are only 20, instead of 62, then the condition is false, causing LINE C to execute, printing Fail.

THINGS TO TRY
  • Try the below code.
    int a = 10;
    int b = 5;
    if (a > b)
        System.out.println("a is greater than b");
    else
        System.out.println("b is greate than a");
    The output should be a is greater than b, since the value of a is greater than b.
  • Try the below code.
    int a = 10;
    int b = 9;
    if (a > b)
        System.out.println("a is greater than b");
    System.out.println("I am not in if block");
    The output should be as shown.
    a is greater than b
    I am not in if block

    Only the first statement below if condition comes into if block.

© meritcampus 2019

All Rights Reserved.

Open In App