dulindraxe dulindraxe - 1 year ago 139
Java Question

Get computer time

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

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 Source
years = Calendar.getInstance().get(Calendar.YEAR) - yearOfBirth;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download