Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.time.LocalDate;
- import java.time.Period;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int currentMonth,
- currentYear,
- currentAge,
- bornYear,
- bornMonth,
- ny,
- nm;
- System.out.println("Enter the current year:"); currentYear = in.nextInt();
- System.out.println("Enter the current month(1-12 integer)"); currentMonth = in.nextInt();
- System.out.println("Enter your current age in years(integer)"); currentAge = in.nextInt();
- System.out.println("Enter the month in which you were born(1-12 integer)"); bornMonth = in.nextInt();
- System.out.println("Enter the year for which you wish to know your age:"); ny = in.nextInt();
- System.out.println("Enter the month in " + ny + " for which you wish to know your age:"); nm = in.nextInt();
- if(currentMonth > bornMonth)
- bornYear = currentYear - currentAge;
- else
- bornYear = currentYear - currentAge - 1;
- LocalDate bornDate = LocalDate.of(bornYear, bornMonth, 01);
- LocalDate desiredDate = LocalDate.of(ny, nm, 01);
- Period dif = Period.between(bornDate, desiredDate);
- System.out.printf("In "+nm+"/"+ny+" your age will be:" + dif.getYears() + " years and " + dif.getMonths() + " month(s).");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement