Комментарии:
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");
}
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.");}
}
}
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?
Is it just intro
Or is there something else?
can you plz tell why there is so many else conditions
Ответитьthanxx
ОтветитьGood one sir
Ответить