This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar Code Help  RSS feed

 
Nick Tran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Carey Brown
Bartender
Posts: 2993
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you cut&paste a session here so that we can see the input and output you are talking about?
 
Nick Tran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enter Day:
3
Enter the number of days in each month:
29
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
29

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

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
29
 
Nick Tran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Tran wrote:. . .
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!