Java Program for Finding Leap Year or Not

Java Program for Finding Leap Year or Not

TrainingMug

6 лет назад

4,983 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Pure Desi Khana
Pure Desi Khana - 09.10.2021 19:09

code is too long and it takes more time to compile
simply you can write like this
psvmain()
Scanner reference=new Scanner(System.in);
sysout("enter the year");
int year=reference.nextInt();
if(year%4==0 && year%100!=0 || year%400==0)
{
sysout("is a leap year");
}
else
{
sysout("not a leap year");
}

Ответить
Pew
Pew - 05.09.2021 22:04

this code is bad every code i see has leap=true; but in college that isnt even spoken about.

idk if this works but this is mine:

//A year is a leap year if it is divisible by 4. However, if the year is divisible by 100, then it is a leap year only when it is also divisible by 400.

import java.util.Scanner;

public class LeapYear {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);

System.out.println("Give a year: ");

int number = Integer.valueOf(scan.nextLine());



if( number%4==0&& number%400==0){System.out.println("The year is a leap year.");}

else if ( (number%100==0) ){System.out.println("The year is not a leap year.");}

else {System.out.println("The year is not a leap year.");}


}
}

Ответить
B & W Vidventures
B & W Vidventures - 03.05.2021 13:52

what if i want to print that
month is february 29 2025 or 02 29 2025.... 2025 is not a leap year but i want to print that the 29 is invalid . do u know how?

Ответить
Ceramic Pots
Ceramic Pots - 16.03.2021 18:15

Is it just intro
Or is there something else?

Ответить
Thank You
Thank You - 10.06.2020 18:22

can you plz tell why there is so many else conditions

Ответить
GAMER Soul
GAMER Soul - 15.04.2020 12:42

thanxx

Ответить
kesava mannem
kesava mannem - 16.05.2018 13:50

Good one sir

Ответить