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
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.