whats wrong with this?
Could somone plz tell me what I'm doing wrong? I'm learning =/
public static int daysOfMonth (int days) {
switch (days) {
case 1:
case 2:
case 3:
days = 31;
break;
case 4:
case 5:
days = 28;
break;
default:
days = 0;
}
return days;
}
}
[346 byte] By [
TripDsa] at [2007-10-2 15:08:49]

What is it supposed to do? Even once you fix the syntax of the braces, it is confusing. What "days" are you passing in? Why are you using the parameter as a place to store the return value? This certainly isn't a daysOfMonth in the standard Gregorian calendar (January to December).
MLRona at 2007-7-13 14:02:39 >

no thats not it. in eclipse. theres a red line before and after the (int userinput) saying "; expected"
public class PracticeAgain {
/**
* @param args
*/
public static void main(String[] args) {
public static int daysOfMonth (int userinput) {
switch (days) {
case 1:
case 2:
case 3:
days = 31;
break;
case 4:
case 5:
days = 28;
break;
default:
days = 0;
}
return days;
}
}
}
Also, I'm not sure what you are doing but you have 3 conditions where days = 31 and you two conditions where days=28, plus a default where days=0. It seems wrong that there is no case in which days=30, not to mention that there is typically 7 cases where days=31 and 4 cases where days=30 and 1 case where days =29.
You can't define a method inside another method. Move daysOfMonth so that it is OUTSIDE of the main method (but inside the braces of PracticeAgain).
Also, please use code tags (see button above posting box). It makes your code easier to read. Especially helpful in spotting errors like misplaced braces.
MLRona at 2007-7-13 14:02:39 >

> no thats not it. in eclipse. theres a red line
> before and after the (int userinput) saying ";
> expected"
What you first posted had an } too much. Now you're posting omething different.
Don't post that daysOfMonth(...) method within your main(...) method.
> o sorry i was just randomly making some little thing just to practice switches in general. but yea the
> only problem was that it was in the main method. sorry ppl. thanks.
No need to apologize. When you don't explain "what's wrong?", people will take guesses. Even if you do explain "what's wrong?", people will often give you advice on making your code better. Best way to learn (if you follow people who know what they are doing, anyway)!
Glad it works!
MLRona at 2007-7-13 14:02:39 >
