This is the code I have, and when I run it, it works to an extent. I wanted the days to be slid over x amount of spaces depending on what the user would input (Sun = 0, Mon = 1... etc.) but that's where i'm stuck, I've tried myself, but when i do the numbers don't carry over but instead pop out of the grid
Enter the number of days in each month:
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
All the the numbers are lined up good on the right but it won't start at Tuesday (which is the 3rd day) and when i tried hard coding if statements to use the user input amount of days to move a x amount of spaces, the loop still continues to loop which leads the numbers to go beyond Sat
Nick Tran wrote:All the the numbers are lined up good on the right but it won't start at Tuesday (which is the 3rd day)...
Well that's wrong for a start. If Sunday=0, then 3 is Wednesday.
Also: your loops only work for 5 x 7 days. What if the month is 31 days long and starts on a Saturday?
My advice: Turn off your computer and get out lots of paper and work out how YOU would do this. You clearly have the grid printing working, now you just need to work out how to "offset" the days when a month doesn't start on a Sunday.
Programming is about thinking, not about coding.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Why are you creating a new PrintWriter when System.out already is a PrintWriter? Since you are not using any formatting tags, why not simply write:-
System.out.println("Sun " + "Mon " + "Tue " + "Wed " + "Thu " + "Fri " + "Sat "); If you need a new line after printf, write %n