borkins

Exam Jan-2016 - 05. Date after Five Days

May 11th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /**
  2.  * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _05_DateAfterFiveDays
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int day = Integer.parseInt(console.nextLine());
  14.         int month = Integer.parseInt(console.nextLine());
  15.        
  16.         int days;
  17.         int newDay;
  18.         int newMonth;
  19.        
  20.         switch (month) {
  21.             case 2: days = 28; break;
  22.             case 4:
  23.             case 6:
  24.             case 9:
  25.             case 11: days = 30; break;
  26.             default: days = 31;
  27.         }
  28.        
  29.         if (day + 5 <= days) {
  30.             newDay = day + 5;
  31.             newMonth = month;
  32.         }
  33.         else {
  34.             newDay = (day + 5) - days;
  35.             newMonth = ((month < 12) ? (month + 1) : 1);
  36.         }
  37.        
  38.         System.out.printf("%d.%02d%n", newDay, newMonth);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment