1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivolga24 [154]
3 years ago
14

In this lab, you declare and initialize variables in a Java program. The program file named NewAge.java, calculates your age in

the year 2050.
Computers and Technology
1 answer:
Romashka-Z-Leto [24]3 years ago
3 0

Answer:

import java.util.Calendar;

import java.util.Date;

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       System.out.print("Insert Date of Birth: ");

       String[] dateofbirth = new String[3];

       Scanner s1 = new Scanner(System.in);

       int a=0;

       while (a<=2) {

           dateofbirth[a] = s1.next();

           a++;

       }

       System.out.print("Insert future date: ");

       String[] futuredate = new String[3];

       Scanner t1 = new Scanner(System.in);

       a=0;

       while (a<=2) {

           futuredate[a] = t1.next();

           a++;

       }

       Calendar cal1 = Calendar.getInstance();

       cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateofbirth[0]));

       cal1.set(Calendar.MONTH, Integer.parseInt(dateofbirth[1]));

       cal1.set(Calendar.YEAR, Integer.parseInt(dateofbirth[2]));

       Date first_Date = cal1.getTime();

       cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(futuredate[0]));

       cal1.set(Calendar.MONTH, Integer.parseInt(futuredate[1]));

       cal1.set(Calendar.YEAR, Integer.parseInt(futuredate[2]));

       Date second_Date = cal1.getTime();

       long diff = second_Date.getTime() - first_Date.getTime();

       System.out.println ("Age in Days: " + diff / 1000 / 60 / 60 / 24/365);

   }

}

Explanation:

Please check the answer section. In this program we have created two strings, and inpit two dates through them. And then we parse the string items, and store the days, months and years in the calander instance, and we create two such instance. And finally, we find the differene and print the age in days.

You might be interested in
Write a program that will take an integer and add up each of the number’s digits, count the number of digits in the number, and
Inga [223]
For count digits, you could just convert it to a String and check the length
Sum digits, convert to string then seperate each character with charAt then convert it to numbers in the return statement.
Average digits you can convert it to a String and then convert them back after taking them apart.
5 0
3 years ago
Read 2 more answers
Which website can help you find antivirus software ?
sergey [27]

If you have windows you have Windows Defender Installed already!!

5 0
3 years ago
How to control what is on the x and y axis in excel?
kozerog [31]
The value on X you choose first and create a graph then you add values to graphs Y axis.
8 0
3 years ago
Unscramble thr words <br>1.Nsieg Wiev<br>2.Seeathdat ievw​
valentinak56 [21]

Answer: genis view       headset view

Explanation:

6 0
3 years ago
Read 2 more answers
Question 5 (frue/False Worth 3 points)
azamat

<em><u>true</u></em>

Explanation:

<em><u>because</u></em><em><u> </u></em><em><u>logical</u></em><em><u> </u></em><em><u>errors</u></em><em><u> </u></em><em><u>are</u></em><em><u> </u></em><em><u>made</u></em><em><u> </u></em><em><u>to</u></em><em><u> </u></em><em><u>be</u></em><em><u> </u></em><em><u>unexpected</u></em><em><u> </u></em><em><u>it</u></em><em><u> </u></em><em><u>was</u></em><em><u> </u></em><em><u>before</u></em>

5 0
3 years ago
Other questions:
  • Why is it a mistake to put email addresses of people who don't know each other in the "To:" field?
    8·2 answers
  • Which one of the following statements is correct? a. Web browsers cannot function without cookies. b. Cookies are text files and
    9·1 answer
  • An organization is assigned a Class-C network 200.120.80.0 and wants to form subnets for its threedepartments: D1 (60hosts), D2
    7·1 answer
  • Cloud computing is an old phenomenon in computing infrastructure dating back to the early days of the Internet that involves mov
    10·1 answer
  • The process of identifying and eliminating bugs in a software program is most generally called
    5·1 answer
  • Describe in detail what each step would look like if you ran into a software error.
    7·1 answer
  • Explain any two features of a computer​
    15·1 answer
  • Sample outputs with inputs 9 5 2 -1 in python.
    8·1 answer
  • In which of the following situations would it be most appropriate to choose lossy compression over lossless compression?
    5·1 answer
  • When an EC2 instance is being modified to have more RAM, is this considered Scaling Up or Scaling Out?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!