File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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!