IF ELSE STATEMENT IN JAVA
INTRODUCTION
If else statement is used to implement at most two logical conditions.
In the If-else control statement, If statement executes when the test condition is true and else part execute when the test condition would be false.
IF ELSE SYNTAX IN JAVA
if (logical condition)
{
statements ...
}
else
{
statements ...
}
IF ELSE PROGRAM IN JAVA
class result
{
public static void main(String as[])
{
int m=34;
// Logical condition to calculate result
if(m >= 33)
{
System.out.println("Congrats, you are pass");
}
else
System.out.println("Oops, you are failed");
}
}
- - - PROGRAM OUTPUT - - -
LEAP YEAR PROGRAM IN JAVA
class leap_year
{
public static void main(String as[])
{
int year=2020;
if(year % 4 == 0)
{
System.out.println("Leap year");
}
else
System.out.println("Not leap year");
}
}
- - - PROGRAM OUTPUT - - -
EVEN ODD PROGRAM IN JAVA
class even_odd
{
public static void main(String as[])
{
int num=10;
if(num%2 == 0)
{
System.out.println("Even number");
}
else
System.out.println("Odd number");
}
}
{
public static void main(String as[])
{
int num=10;
if(num%2 == 0)
{
System.out.println("Even number");
}
else
System.out.println("Odd number");
}
}
- - - PROGRAM OUTPUT - - -
0 Comments