if statement
int a=10, b=5;
if (a>b)
{
System.out.println("True");
}
Output
if (Marks< 12) {
System.out.println("Bad");
}
Output
}
Output
True
if else statement
int a=10, b=5;
if (a<b)
{
System.out.println("True");
}
}
else
{
System.out.println("False");
}
Output
False
else if statement
int Marks= 30;if (Marks< 12) {
System.out.println("Bad");
}
else if (Marks< 20)
{
System.out.println("Good");
}
System.out.println("Good");
}
else
{
System.out.println("Excellent");
}
System.out.println("Excellent");
}
Output
Excellent
Nested if else
int a = 8;
if (a == 8)
{
if (a < 16)
System.out.println("a is smaller than 16");
if (a < 18)
System.out.println("a is smaller than 18");
else
System.out.println("a is greater than 18");
}
}
}
Output
a is smaller than 16
a is smaller than 18
0 Comments