Menu
Topics Index
...
`

Simple if example output


If you need explanation Read this topic

If you need Answer Take test on this topic

Simple if example output
What will be the output of the following program?
class IfExample
{
    public static void main(String s[])
    {
        if( 1 > 2 )
        {
            System.out.println(" 1 is greater than 2");
        }
    }
}

A. "No output".
B. 1 is greater than 2
C. 2 is greater than 1
D. Runtime error.
Topic: if Condition In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is A...here we have the simple if statement..if is used to select one statement out of 2 statements based on the Condition...
here we have with some condition..here condition is false so control wont goes into the if block..it will look for the else block bu here we did not write any else block so no output...else block is optional for the if...but every else must contain if block

Posted by Uday Kumar    2014-12-19 08:31:22


Ans is A.
This program is using if statment it will pass to print only when if condition is satisfied. So there is no other statement to print

Posted by Fuzail Ahmed    2014-12-19 08:50:45


ans a. basically if statement has 2 different statement block, if block and else block.based on the given condition result any one of the block get executed. else block is an optional.coming to this program if statement checks 1>2 ,1 is less than 2 so given condition failed ,if block not get executed, here we have ly if block.so no output get printed. result is empty.but program compile and run successfully

Posted by Maheshwari Natarajan    2014-12-19 17:55:13


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Mânïshå Mùlchåndânï. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-22 06:52:43


© meritcampus 2019

All Rights Reserved.

Open In App