Consider the following program written in Java.
class Test{
public static void main(String args[]){
int x=7;
if(x==2); // Note the semicolon
System.out.println("NumberSeven");
System.out.println("NotSeven");
}
}
What would the output of the program be?
class Test{
public static void main(String args[]){
int x=7;
if(x==2); // Note the semicolon
System.out.println("NumberSeven");
System.out.println("NotSeven");
}
}
A. NumberSeven NotSeven
B. NumberSeven
C. NotSeven
D. Error
E. 7
Answer: Option A
Join The Discussion
Comments ( 2 )
Related Questions on Flow Control
What is the purpose of the "if" statement in Java?
A. To execute a block of code conditionally
B. To create loops
C. To declare variables
D. To define methods
A. No output
B. Error
C. Hello
D. 5
if you put a semicolon directly after the condition in an if statement, the java program thinks it's finished with the body of the statement. The indentation of the next line is ignored by Java and it prints everything,,,,,,in this case the output is A
How this is possible to write semicolon after if statement ?please help someone.