Advertisement
cd62131

Age

Jul 6th, 2014
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.73 KB | None | 0 0
  1. import java.util.Calendar;
  2. import java.util.GregorianCalendar;
  3.  
  4. public class Age {
  5.   public static void main(String[] args) {
  6.     int birth_year = 1990, birth_month = 4, birth_day = 25;
  7.     Calendar birth = new GregorianCalendar(birth_year, birth_month - 1, birth_day);
  8.     Calendar today = new GregorianCalendar();
  9.     int age = today.get(Calendar.YEAR) - birth_year;
  10.     if (today.get(Calendar.MONTH) == birth_month && today.get(Calendar.DAY_OF_MONTH) < birth_day)
  11.       age--;
  12.     else if (today.get(Calendar.MONTH) < birth_month)
  13.       age--;
  14.     System.out.format("%tY年%tm月%td日生まれ\n", birth, birth, birth);
  15.     System.out.format("%d歳です。(%tY年%tm月%td日現在)\n", age, today, today, today);
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement