This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Calendar weirdness... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar weirdness..." Watch "Calendar weirdness..." New topic

Calendar weirdness...

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I'm trying to develop a simple method that prints the day, month, day number, and year from the current day forward for 4 months.

For example, from today forward it would start like this:

I've got it working but something strange happens when it rolls past the current year....the loop becomes infinite and it doesn't stop after 4 months! If it doesn't go beyond the current only shows 4 months worth of lines!

Here's my code:

Why does it not stop after 4 months if it rolls past Dec of the current year? I know I must be missing something obvious but I'm getting fatigued w/ it...hopefully someone can explain?

fred Joly
Ranch Hand

Joined: Jan 19, 2006
Posts: 55
You said "month" is an int.
So imagine you start in month = 10.
I guess Calendar.MONTH is always smaller than 14....
I agree. Here's the link:
subject: Calendar weirdness...
It's not a secret anymore!