// This program calculates your age in the year 2050. // Input: None. // Output:
ID: 3791696 • Letter: #
Question
// This program calculates your age in the year 2050.
// Input: None.
// Output: Your current age followed by your age in 2050.
public class NewAge2
{
public static void main(String args[])
{
int currentAge = 25;
int newAge;
int currentYear = 2014;
// Declare a constant named YEAR and initialize it to 2050
// Edit this statement so that it uses the constant named YEAR.
newAge = currentAge + (2050 - currentYear);
System.out.println("My Current Age is " + currentAge);
// Edit this output statement so that is uses the constant named YEAR.
System.out.println("I will be " + newAge + " in 2050.");
System.exit(0);
}
}
1. Decalre a constant named YEAR, and initialize YEAR with the value 2050.
2. edit the following statement so it uses the constant names YEAR:
newAge = currentAge + (2050 - currentYear);
3. edit the following statement so it uses the constant names YEAR:
system.out.println("I will be" + newAge + "in 2050.");
4. Compile source code NewAge2.java
5. execute
Explanation / Answer
public class NewAge2
{
public static void main(String args[])
{
final int constant = 2050;
int currentAge = 25;
int newAge;
int currentYear = 2014;
// Declare a constant named YEAR and initialize it to 2050
// Edit this statement so that it uses the constant named YEAR.
newAge = currentAge + (constant - currentYear);
System.out.println("My Current Age is " + currentAge);
// Edit this output statement so that is uses the constant named YEAR.
System.out.println("I will be " + newAge + " in "+ constant);
System.exit(0);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.