135k views
12 votes
9.

Write an application that computes and displays the day on which you become (or
became) 10,000 days old. Save the application as Ten ThousandDaysOld.java.
TI

User Bdimag
by
4.6k points

2 Answers

10 votes

Final answer:

To compute and display the day on which you become 10,000 days old, you can use the java.util.Calendar class in a Java application.

Step-by-step explanation:

To write an application that computes and displays the day on which you become 10,000 days old, you can use the java.util.Calendar class and its methods. Here is an example code:

import java.util.Calendar;

public class TenThousandDaysOld {
public static void main(String[] args) {
Calendar birthdate = Calendar.getInstance();
birthdate.add(Calendar.DAY_OF_YEAR, 10000);

int day = birthdate.get(Calendar.DAY_OF_MONTH);
int month = birthdate.get(Calendar.MONTH) + 1;
int year = birthdate.get(Calendar.YEAR);

System.out.println("You will be 10,000 days old on " + month + "/" + day + "/" + year);
}
}

This application creates a Calendar object representing the current date, then adds 10,000 days to it. It then retrieves the day, month, and year from the updated Calendar object and displays it.

User Praveesh P
by
5.5k points
11 votes

Answer:

Step-by-step explanation:

The following code is written in Java and it asks you for your age and then prints out the exact date from your birthday that you will turn 10,000 days old.

import java.util.Calendar;

import java.util.Date;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("What is your age?");

int age = in.nextInt();

int daysLeft = (10000 - (age*365));

Date birthday = new Date();

Calendar cal = Calendar.getInstance();

cal.setTime(birthday);

cal.add(Calendar.DATE, daysLeft);

Date modifiedDate = cal.getTime();

System.out.println(modifiedDate);

}

}

User Ropo
by
4.9k points