I once spent two hours wondering why my method called throw() wouldn't compile.
Paul Clapham wrote:. . . Yeah, we've all been there. I remember... . . .
You're such an incurable optimist, aren't you, Paul
on to the next tar pit!
You seem to have lots of static imports, but are you actually using them?
Jeremiah Waters wrote: . . .
Please don't go thinking there is anything important about the main method. It is like the Union Flag at the Grand Prix at Silverstone. The Union Flag isn't really important: the cars are the important part. It is there for starting the application but there is nothing important about the main method. More information here.
The following code is in the main of another class (LeapYear.java).
Don't change your code to correct the error messages. Use the error messages to find the error in your code and change the code to correct the errors. A method with a name starting is should usually return a boolean (not a Boolean). So make your method return a boolean, and run your code until you can pass years and get the results true or false. That shouldn't take long. Note what this old style guide says about boolean returns.
[code=java:fistline]public static String isLeapYear( int year )
//The String above was originally Boolean, but I changed it because Boolean caused a whole other sling of errors.[/code]
Program to the design of your application, not to get rid of the compiler errors. You have two options. You can design a class representing a year, in which case it would have a year number as a field and a method to show whether it is a leap year. That is one option. You would not have a method taking a year number to show whether it is a leap year. That means you have to create a standard Java® class and make objects from it.
Attempt to fix 1: . . .
No, that isn't what postincrement means. The variable is incremented as part of the current statement, following the usual rules of left‑to‑right execution and precedence. The value is however invisible until the variable is used next.
meenal deshpande wrote:. . . post increment, which means increment the variable after executing current statement.
Afraid that doesn't. This last bit might be correct, but if you are showing it in contrast to postincrement it simply causes confusion.
. . . pre increment, which means increment the variable in current statement itself.
Hope it helps.
That part is correct. You missed out that i is 2 and j is 1 in the last line.
++i will increment the value of i, and then return the incremented value.
i = 1;
j = ++i;
(i is 2, j is 2)
i++ will increment the value of i, but return the original value that i held before being incremented.
i = 1;
j = i++;