Question #139475

Write a program that asks a user for their birth year encoded as two digits (like "62")
and for the current year, also encoded as two digits (like "99"). The program is to
correctly write out the users age in years.

Expert's answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the birth year");
        int birth = in.nextInt();
        System.out.println("Enter the current year:");
        int current = in.nextInt();
        System.out.println("The age is: " + (current - birth));
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS