Advertisement
Guest User

ex 10

a guest
Jan 28th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import java.time.LocalDate;
  5. import java.time.Period;
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args) {
  10. Scanner in = new Scanner(System.in);
  11. int currentMonth,
  12. currentYear,
  13. currentAge,
  14. bornYear,
  15. bornMonth,
  16. ny,
  17. nm;
  18. System.out.println("Enter the current year:"); currentYear = in.nextInt();
  19. System.out.println("Enter the current month(1-12 integer)"); currentMonth = in.nextInt();
  20. System.out.println("Enter your current age in years(integer)"); currentAge = in.nextInt();
  21. System.out.println("Enter the month in which you were born(1-12 integer)"); bornMonth = in.nextInt();
  22. System.out.println("Enter the year for which you wish to know your age:"); ny = in.nextInt();
  23. System.out.println("Enter the month in " + ny + " for which you wish to know your age:"); nm = in.nextInt();
  24.  
  25. if(currentMonth > bornMonth)
  26. bornYear = currentYear - currentAge;
  27. else
  28. bornYear = currentYear - currentAge - 1;
  29. LocalDate bornDate = LocalDate.of(bornYear, bornMonth, 01);
  30. LocalDate desiredDate = LocalDate.of(ny, nm, 01);
  31. Period dif = Period.between(bornDate, desiredDate);
  32. System.out.printf("In "+nm+"/"+ny+" your age will be:" + dif.getYears() + " years and " + dif.getMonths() + " month(s).");
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement