English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Neste programa, você aprenderá a verificar se um ano específico é bissexto. Use statements if else para verificar.
o ano bissexto pode ser4divisível, mas terminando em 00. Apenas quando for4divisível por 100, o ano bissexto é o século
public class LeapYear { public static void main(String[] args) { int ano = 1900; boolean saltarAno = false; if(ano % 4 == 0) { if(ano % 100 == 0) { //Year can be divided by400 is divisible by, therefore it is a leap year if ( year % 400 == 0) leap = true; else leap = false; } else leap = true; } else leap = false; if(leap) System.out.println(year + " is a leap year."); else System.out.println(year + " is not a leap year."); } }
The output when running the program is:
1900 is not a leap year.
Change the value of year to2012The output is:
2012 is a leap year.
In the above program, the given year1900 is stored in the variable year.
because1900 is divisible by4divisible and it is a century year (ending with 00), while leap years can be divided by4divisible by 00. Because1900 is not divisible by4divisible by 00, so1900 is not a leap year.
However, if we change year to2000, then it can be4divisible and it is a century year, which can also be divided by4divisible by 00. Therefore2000 is a leap year.
Similarly, if we change the year to2012then the year can be divided by4divisible and it is not a century year, so2012It is a leap year. We do not need to check2012Year can be divided by400 is divisible by.