// yourAge.java // by ChanJin Chung // Not year 2000 compliant import java.io.DataInputStream; import java.lang.String; import java.lang.Integer; import java.io.IOException; import java.util.Date; class yourAge { public static void main(String args[]) { DataInputStream dis = new DataInputStream(System.in); String name=null; String yyStr=null; int yy; System.out.print("Enter your name: "); System.out.flush(); // instead of "println" try { name = dis.readLine(); } catch (IOException ioe) { System.out.println(ioe.toString()); System.exit(1); } System.out.print("Enter your birth YY: "); System.out.flush(); try { yyStr = dis.readLine(); } catch (IOException ioe) { System.out.println(ioe.toString()); System.exit(1); } yy = Integer.parseInt(yyStr); // if you enter "ab" for yy,... System.out.println("Your Name: " + name); System.out.println("Your birth year: " + yy); Date today = new Date(); int cyy = today.getYear(); System.out.println("Today is " + today.toString()); System.out.println("Today's YY = " + cyy); System.out.println(name + ", your age is about " + (cyy - yy) ); } }