Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- public class Age {
- public static void main(String[] args) {
- int birth_year = 1990, birth_month = 4, birth_day = 25;
- Calendar birth = new GregorianCalendar(birth_year, birth_month - 1, birth_day);
- Calendar today = new GregorianCalendar();
- int age = today.get(Calendar.YEAR) - birth_year;
- if (today.get(Calendar.MONTH) == birth_month && today.get(Calendar.DAY_OF_MONTH) < birth_day)
- age--;
- else if (today.get(Calendar.MONTH) < birth_month)
- age--;
- System.out.format("%tY年%tm月%td日生まれ\n", birth, birth, birth);
- System.out.format("%d歳です。(%tY年%tm月%td日現在)\n", age, today, today, today);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement