dulindraxe dulindraxe - 1 month ago 17
Java Question

Get computer time

I would like to know how I can tell to this simple program to replace the

"2016-yearOfBirth"
string with a
"computer time - yearOfBirth"
.

I don't know how to set the computer time as an int and how to proceed...

public static void main(String[] args) {
Scanner in;
int yearOfBirth, years;
in = new Scanner (System.in);
System.out.print ("Year of Birth: ");
yearOfBirth = in.nextInt();
years = 2016 - yearOfBirth;
System.out.println("You are almost "+years+" years old");
}

Answer
years = Calendar.getInstance().get(Calendar.YEAR) - yearOfBirth;