class Try{
public static void main(String[] arg){
int a=5;
if(a==5)
System.out.println("b");
else
System.out.println("c");
}
}
class Try{
public static void main(String[] arg){
int a=5;
if(a==5)
System.out.println("b");
else
System.out.println("c");
}
}
What do you think the difference is between the above programs?
->In the first program, the if and else are not enclosed
with curly braces {}
->In the second program, the if and else are enclosed with
curly braces{}
What is the output?
->For first "b" is the output
->For the second, "b" is the output
I thought for a second that a program error would occur because curly braces are not there, but the output is
"b"
In the second case
class Try{
public static void main(String[] arg){
int a=5;
if(a==5)
System.out.println("b");
System.out.println("a");
else
System.out.println("c");
}
}
When we are using one statement in the program, it is running
Well, without any error, but in the second
output
Top comments (0)