This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Leap Year program

 
Benjamin Chau
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, this Leap Year program is really starting to get to me. While seemingly simple, here are the error messages I get when I try to compile.

C:\Documents and Settings\Benjamin Q. Chau\WRITTENPROGRAMS>javac Leap.java
Leap.java:13: '.class' expected
if (boolean == true)
^
Leap.java:28: ')' expected
^
Leap.java:29: illegal start of expression
}
^
3 errors

Why would I need to tag on ".class" to the boolean keyword? Overall, I'm not understanding why I'm getting these error messages. I checked and checked to make sure I closed all brackets/parantheses. Any help would be great. Here's my code:


[ November 17, 2008: Message edited by: Benjamin Chau ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on HTML.

For more information, please read this.

This post has been moved to a more appropriate forum.
 
Benjamin Chau
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh sorry Bear, didn't realize what forum I was in...

Benjamin
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Benjamin Chau



In the above statement you are check year which is a int.And it does NOT result in boolean value. && operator looks for something which results in boolean(true or false) ONLY.

And what is that you are checking by 100 != 100??? Is not at all need ...

And i doubt the condition that you are checking is correrct.

Try this..
boolean isLeapYear = ((year % 4 == 0) ||(year % 400 == 0));
 
Benjamin Chau
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,

Thanks for pointing out those errors. Actually, I still need that middle condition because that partly defines a Leap Year so I left it in. Here's the error message I get now when I try to compile:


C:\Documents and Settings\Benjamin Q. Chau\WRITTENPROGRAMS>javac Leap.java
Leap.java:13: '.class' expected
if (boolean == true)
^
Leap.java:28: ')' expected
^
Leap.java:29: illegal start of expression
}
^
3 errors



And here's my modified code:



[ November 17, 2008: Message edited by: Benjamin Chau ]
[ November 18, 2008: Message edited by: Benjamin Chau ]
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think boolean should be replaced by isLeapYear.
boolean is a data type ... you can't do what you are trying there

do this..
if (isLeapYear==true)
 
Benjamin Chau
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's it! YOU'RE AWESOME! THANKS! Don't know why I used the boolean variable that way...

Benjamin
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"boolean" isn't a variable, but a keyword. You mustn't used keywords or other reserved words out of their intended context.

"== false" and "== true" are errors. If you write = false by mistake. you can get all sorts of errors. You write if(leapYear) or if(!leapYear).
 
Benjamin Chau
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell. That was silly of me to use boolean as a variable. These late nighters screw with your mind I guess. I'm going back to edit the code now.

James suggested I change the syntax around a bit in one of his earlier posts but I've been thinking that that would change the logic and make the Leap Year program not work correctly. So I took that into account in my editing...

Benjamin
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It ought to readNever use == false or == true because you can get nasty errors if you write = instead of == by mistake.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic