Answer to Question #236280 in Java | JSP | JSF for guru

Question #236280

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-12T18:48:11-0400


package decades;




import java.util.Scanner;
public class Decades {


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

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