How to use if statement in java program ?
Previous | Home | Next |
In this program if else statement is used . if else statement used to check the condition
In this program we check the year whether it is leap or not.
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
is used to check whether the condition is true or not.
a variable Year is taken and assign value 2011
in if block conditions are given , if conditions are fulfill then the year is leap
in else block otherwise statement is print.
public class Leapyear {
public static void main(String[] args) {
int year = 2011;
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
System.out.println("Year " + year + " is a leap year");
else
System.out.println("Year " + year + " is not a leap year");
}
Previous | Home | Next |