Question

1, a java program that ask the user for their name and the year they were...

1, a java program that ask the user for their name and the year they were born. Display the name of the user and their age in years.

Homework Answers

Answer #1
//YearToAge.java
import java.util.Scanner;
public class YearToAge {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter name: ");
        String name = scanner.nextLine();
        System.out.print("Enter year you born: ");
        int year = scanner.nextInt();
        int age = 2020-year;

        System.out.println(name+" is "+age+" years old");
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
Classwork_1.5: Write a C code that ask the user to enter the name of person, gender...
Classwork_1.5: Write a C code that ask the user to enter the name of person, gender (male or female) and age and display these quantities. You need to create a structure to solve this problem. Output:
B.2. Write a Java program to display a dialog box that asks you to enter your...
B.2. Write a Java program to display a dialog box that asks you to enter your user name and the age as shown below: The program displays in a dialog box the sum of digits of your age. For example, if you age is 19, the sum will be 1+9 = 10 and the output will be as shown below: ( it just shows a message box that says the sum of the digits age of john is 10.
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
Write a program that asks the user for the name of a file. The program should...
Write a program that asks the user for the name of a file. The program should display only the first five lines of the file’s contents. If the file contains less than five lines, it should display the file’s entire contents. by python using while loop
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask...
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4, end the program....
Write a C program to ask the user 3 number and display in the greater value...
Write a C program to ask the user 3 number and display in the greater value from it. Only use compound condition in if-Else statements.
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
Write a Java program that reads employee information from the file “employee.txt” then the program will...
Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen. The file contains the Employee’s Name, age,join date, quit date, and salary. • For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed. • For each year the employee is in the company, one-month salary...