+ 2

Can anyone solve this?

A program which takes the number of days as input from the user.The program calculates the nth day and the month.For example the input :52 then the output :21st February

23rd Mar 2018, 1:46 PM
Napster
Napster - avatar
10 Respostas
+ 6
Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2014); cal.set(Calendar.DAY_OF_YEAR, 1); Date start = cal.getTime(); System.out.println(start); cal.add(Calendar.DATE, 51); Date end = cal.getTime(); System.out.println(end);
23rd Mar 2018, 2:03 PM
Geo
Geo - avatar
+ 6
@Geo Honestly, was hard to understand the question so I just winged it. lol Even as I read it again right now, I can't tell which one of us is correct in addressing their issue, especially since they didn't bother to reply back to either of us or provide sufficient information. Whatever their real question is, I think between me and you they have enough information to come up with their result.
23rd Mar 2018, 3:00 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 5
I think this is what you're looking for. Hope it helps. https://code.sololearn.com/cP73C49k0aQV/#java import java.util.Scanner; import java.util.Date; import java.util.GregorianCalendar; public class Program { public static void main(String[] args) { GregorianCalendar targetDate = new GregorianCalendar(); // our calendar object Scanner scnr = new Scanner(System.in); // our input object int userInput = 0; // Obtain input from user in DAYS System.out.println("Please enter number of days: "); userInput = Integer.parseInt(scnr.nextLine()); // Subtract user's input against our calendar object targetDate.add(GregorianCalendar.DAY_OF_MONTH, -userInput); // Print our date/time. System.out.println(targetDate.getTime()); } } :::: INPUT :::: 7 :::: OUTPUT :::: Please enter number of days: 7 Fri Mar 16 14:06:04 UTC 2018
23rd Mar 2018, 2:05 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 5
@Jakob I think he want N th day after the 01/01 of a year. Your code give the N th day before today.
23rd Mar 2018, 2:11 PM
Geo
Geo - avatar
+ 5
@Jakob I agree with you. Let's wait for his answer 👍.
23rd Mar 2018, 3:03 PM
Geo
Geo - avatar
+ 5
Anyway, he will have learned 2 things 😉.
23rd Mar 2018, 3:07 PM
Geo
Geo - avatar
+ 3
@Geo U r right.I want the Nth day after 01/01 of a year
23rd Mar 2018, 3:53 PM
Napster
Napster - avatar
+ 3
@Geo Guess you won. :) @Napster Make sure you mark Geo's answer as correct. (checkmark) This ensures he gets credit for his accepted answer and so others will know which one to reference in regards to your question.
23rd Mar 2018, 4:24 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
@Jakob I share the price with you. I hope it is a pack of beer 🍺
23rd Mar 2018, 6:40 PM
Geo
Geo - avatar
+ 1
@Geo's answer is correct.
23rd Mar 2018, 4:28 PM
Napster
Napster - avatar