SHARE
TWEET

DateAfter5Days

SUni2020 Mar 28th, 2020 (edited) 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top