Advertisement
Venciity

[Java] NextDate

May 6th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. //http://bgcoder.com/Contests/41/Telerik-Academy-Exam-1-27-Dec-2012
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class NextDate {
  10.  
  11.     public static void main(String[] args) {
  12.        
  13.         Scanner sc = new Scanner(System.in);
  14.         int day = sc.nextInt();
  15.         int month = sc.nextInt();
  16.         int year = sc.nextInt();
  17.        
  18.         DateFormat dateFormat = new SimpleDateFormat("d.M.yyyy");
  19.        
  20.         Date date = new Date();
  21.         Calendar cal = Calendar.getInstance();
  22.         cal.setTime(date);
  23.         cal.set(Calendar.DAY_OF_MONTH, day);
  24.         cal.set(Calendar.MONTH, month-1); // month-1 because january = 0 ....
  25.         cal.set(Calendar.YEAR, year);
  26.         cal.add(Calendar.DAY_OF_MONTH, 1);
  27.         date = cal.getTime();
  28.         System.out.println(dateFormat.format(date));
  29.  
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement