SUni2020

DateAfter5Days

Mar 28th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DateAfter5Days {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int day = Integer.parseInt(scanner.nextLine());
  8. int month = Integer.parseInt(scanner.nextLine());
  9.  
  10. int daysInMonth = 31;
  11.  
  12. if( month == 2) {
  13. daysInMonth = 28;
  14. }
  15.  
  16. if (month == 4 || month == 6 || month == 9 || month == 11) {
  17. daysInMonth = 30;
  18. }
  19.  
  20. day +=5;
  21.  
  22. if (day > daysInMonth) {
  23. day -= daysInMonth;
  24. }
  25.  
  26. if (day > daysInMonth) {
  27. day -= daysInMonth;
  28. month++;
  29. if(month > 12) {
  30. month = 1;
  31. }
  32. }
  33. System.out.printf("%d.%02d", day, month);
  34. }
  35. }
Add Comment
Please, Sign In to add comment