Write a JAVA program in which take date(DDMMYYYY) from user and displaynext day date(DDMMYYYY) as output.Example:Input: date=09, month=-06, year=1992Output: date=10, month=-06, year=1992Note:-1. Consider condition for leap year2. Consider number of days in month of February based on leap year ( if leapyear then February days =29, else days = 28 ) )3. Consider number of days either 30 or 31 based on month entered by user
Question
Write a JAVA program in which take date(DDMMYYYY) from user and displaynext day date(DDMMYYYY) as output.Example:Input: date=09, month=-06, year=1992Output: date=10, month=-06, year=1992Note:-1. Consider condition for leap year2. Consider number of days in month of February based on leap year ( if leapyear then February days =29, else days = 28 ) )3. Consider number of days either 30 or 31 based on month entered by user
Solution
Here is a simple Java program that takes a date from the user and displays the next day's date. This program also considers leap years and the number of days in each month.
import java.util.Scanner;
public class NextDay {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter date (DD): ");
int date = scanner.nextInt();
System.out.println("Enter month (MM): ");
int month = scanner.nextInt();
System.out.println("Enter year (YYYY): ");
int year = scanner.nextInt();
if (date < 1 || date > 31 || month < 1 || month > 12) {
System.out.println("Invalid date or month entered.");
return;
}
date++;
if ((month == 4 || month == 6 || month == 9 || month == 11) && date > 30) {
date = 1;
month++;
} else if (month == 2) {
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
if (date > 29) {
date = 1;
month++;
}
} else if (date > 28) {
date = 1;
month++;
}
} else if (date > 31) {
date = 1;
month++;
}
if (month > 12) {
month = 1;
year++;
}
System.out.println("Next day's date is: " + date + "-" + month + "-" + year);
}
}
This program first takes the date, month, and year from the user. It then increments the date by 1. If the date exceeds the maximum number of days in the current month, it resets the date to 1 and increments the month by 1. If the month exceeds 12, it resets the month to 1 and increments the year by 1. The program then prints the next day's date.
Similar Questions
shu wants to create a program that asks users to input their birthdates, including the day, month, and year. The program should then display the entered birthdate in the format "DD/MM/YYYY."Write a program to assist Ishu in achieving this task.Input format :The input consists of three space-separated integer values, representing the user's birthdate(day, month, and year).Output format :The output displays the user's birthdate in the format "Your birthday is on " followed by the formatted date DD/MM/YYYY.
Write a C program that prompts the user to enter the date as three integer values for the month, the day in the month, and the year. The program should then output the date in the form 31st December 2010 when the user enters 12 31 2010, say. The program has to work out when superscripts “th”, “nd”, “st”, and “rd” need to be appended to the day value. The programmer should not forget 1st, 2nd, 3rd, 4th; and then 11th, 12th, 13th, 14th; and 21st, 22nd, 23rd, and 24th.Testcases:Input:02 11 2021Output:11th February 202
Create a class Year to read year and find whether is is leap year or not. Create a class month which display 12 months . Create a class import which uses above classes and tell the current month and year and also tell whether it is leap or not
You are given a year in the form of an integer 'N', and your task is to check whether the given year is a leap year or not.Note:1) A year is said to be a leap year if it has 366 days. Normal years have 365 days.2) The integer 'N' does not contain any leading zeros.Sample Input 1:220002020Sample Output 1:YesYesExplanation for Sample Output 1:In test case 1, The year 2000 had 366 days since there were 29 days in the month of February in the year 2000.
Create a class called Date that includes three pieces of information as instance variables—a month, a day and a year. Your class should have a constructor that initializes the three instance variables after validating the given date. Provide a getDetails() member method to read the date. Provide a method displayDate() that displays the month, day and year separated by forward slashes(/). Write a C++ application and pseudocode that demonstrates classDate’s capabilities.Input : Read Month, Day and Year (Line by line)Output :Print Date that displays the month, day and year separated by forward slashes(/)Note: print "Invalid Date" other than the following2000 < Year < 20250 < Day <= 31 ( for the months Jan, March, May, July, August, October, December)0 < Day <= 30 ( for the months April, June, September, and November)0 < Day <= 28 ( for the month February ) and (0 < Day <= 29), if month = 2 and year = leap year0 < Month < = 12
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.