fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.SimpleDateFormat;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. String date = "2019-05-20";
  15.  
  16. String year = "", month = "", day = "";
  17. String todayYear = "", todayMonth = "", todayDay = "";
  18.  
  19. Date todayDate = new Date();
  20. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  21. String today = formatter.format(todayDate);
  22.  
  23. for(int i=0; i<date.length(); i++){
  24. if(date.charAt(i) == '-') continue;
  25.  
  26. if(i<4) year += date.charAt(i);
  27. else if(i>4 || i<7) month += date.charAt(i);
  28. else if(i>7) day += date.charAt(i);
  29. }
  30.  
  31. for(int i=0; i<today.length(); i++){
  32. if(today.charAt(i) == '-') continue;
  33.  
  34. if(i<4) todayYear += today.charAt(i);
  35. else if(i>4 || i<7) todayMonth += today.charAt(i);
  36. else if(i>7) todayDay += today.charAt(i);
  37. }
  38.  
  39. System.out.println(year+month+day);
  40. System.out.println(todayYear+todayMonth+todayDay);
  41.  
  42.  
  43. int paramYear = Integer.parseInt(year);
  44. int paramMonth = Integer.parseInt(month);
  45. int paramDay = Integer.parseInt(day);
  46. int todayYearInt = Integer.parseInt(todayYear), todayMonthInt = Integer.parseInt(todayMonth), todayDayInt = Integer.parseInt(todayDay);
  47.  
  48. System.out.println(paramYear + " " + paramMonth + " " + paramDay);
  49.  
  50. }
  51. }
Runtime error #stdin #stdout #stderr 0.07s 2184192KB
stdin
Standard input is empty
stdout
20190520
20190526
stderr
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:592)
	at java.lang.Integer.parseInt(Integer.java:615)
	at Ideone.main(Main.java:45)