Answer to Question #237038 in Java | JSP | JSF for Selma Shigwedha

Question #237038
Create a program that reads the users name and year of birth from input(keyboard), then print out
their name and age in decades(find out the meaning).
Sample run 1: Sample run 2:
Enter your name: Hausiku Enter your name: Johanna
Enter your year of birth:1999 Enter your year of birth:2005
Output: Hello Hausiku, you have lived for 2 Output: Hello Johanna, you have lived for 1
decade(s) decade(s).
1
Expert's answer
2021-09-14T09:52:55-0400
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		System.out.print("Enter your name: ");
		Scanner in = new Scanner(System.in);
		String name = in.next();
		System.out.print("Enter your year of birth: ");
		int year = in.nextInt();
		int decades = (2021 - year) / 10;
		System.out.printf("Hello %s, you have lived for %d decade(s)", name, decades);
		in.close();
	}
}






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS