I will lifesaver best result Write a program that asks a user for a date, month,
ID: 3638567 • Letter: I
Question
I will lifesaver best result
Write a program that asks a user for a date, month, day, year separately, and outputs the date of the next day.
don't forget leap year.
The program should ask how many dates you have, before processing the dates, and should have a minimum of 2 methods. one of which minimally returns a value, and the other which minimally accepts at least 1 value. (both can do both)
In the Gregorian calendar 3 criteria must be met to be a leap year:
This means that 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
Explanation / Answer
please rate - thanks
import java.util.*;
class nextDay
{ public static void main(String args[])
{int m,d,y,l,days,n ;
Scanner in=new Scanner(System.in);
System.out.print("How many days? ");
n=in.nextInt();
for(int i=0;i<n;i++)
{
System.out.print("Enter the month: ");
m=in.nextInt();
System.out.print("Enter the day: ");
d=in.nextInt();
System.out.print("Enter the year: ");
y=in.nextInt();
days=getDays(m,y);
d++;
if(d>days)
{d=1;
m++;
if(m>12)
{y++;
m=1;
}
}
System.out.println(m+"/"+d+"/"+y);
}
}
public static int getDays(int m,int year)
{ int days;
switch(m)
{case 9:
case 4:
case 6:
case 11: days=30;
break;
case 2: if(leap(year)==1)
days=29;
else
days=28;
break;
default: days=31;
}
return days;
}
public static int leap(int y)
{if(y%4!=0)
return 0;
if(y%100==0)
if(y%400!=0)
return 0;
return 1;
}
}