I want to get next date by putting the any value. like Today is 10/07/2018 when i give input 10 means I have need next date 20/07/2018.
Asked
Active
Viewed 75 times
-3
-
1Great! What did you try to solve this problem? Please [edit] your question and include the code you have tried. Does it work? – Jul 10 '18 at 13:08
1 Answers
0
Only a few steps are required :
- take user input
- take today's date (using
Modern Java time API
) - add to the date the number of days of the input
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
LocalDate nextDate = nextDate(sc.nextInt());
}
private static LocalDate nextDate(int daysToAdd){
LocalDate today = LocalDate.now();
today = today.plusDays(daysToAdd);
return today;
}
// can be inline in :
// return LocalDate.now().plusDays(int daysToAdd);

azro
- 53,056
- 7
- 34
- 70
-
Using `Scanner` instead of taking the number of days as a parameter prevents this method from being reusable. – David Conrad Jul 10 '18 at 13:17