Originally posted by r035198x
CAn anyone help me wit the?? scanner stdin?
Collapse
X
-
It's not a matter of having to merge them. It's coming up with a simple algorithm. Something like when months entered is in (1, 3, 5, 7, 8,10, 12) then days in month is 31. A switch is well suited for this.Originally posted by shadachiusing the switch... i see .. but i dono how to merge them all .. from the 1st example i posted ..using the switch and the 2nd using the arrays.. how to merge them ...Comment
-
There are lots of solutions as you have already heard in this thread. Write them all if you have time and compare them yourself.Originally posted by shadachiSo ..the better solution is by using the switch??
but nomad suggested I would make a array or an array list which would hold your months and days and then use an if statement using a scanner for the inputComment
-
ERm ..i get the idea d.. but the thing is i don't know much from switch.. i learned not much..can try and put an example..so i can learn? .sorry to bother u so much ><Originally posted by r035198xIt's not a matter of having to merge them. It's coming up with a simple algorithm. Something like when months entered is in (1, 3, 5, 7, 8,10, 12) then days in month is 31. A switch is well suited for this.Comment
-
I'm afraid if I give you the link to the tutorial for it, I'll have spoilt it for you and given you the answer ....Originally posted by shadachiERm ..i get the idea d.. but the thing is i don't know much from switch.. i learned not much..can try and put an example..so i can learn? .sorry to bother u so much ><
Don't have some text book that describes it? Even in c+, the concept/syntax is the same?Comment
-
-
Originally posted by r035198xHere's one that looks safe enough.
in the switch statement rite?
i put
the output i got. is the number of days in 1,2006 is 31.Code:switch(month){ case1: case3; case5; numdays=31; break; default: System.out.println("Invalid month."); break; } System.out.println("The Number of Days in " +month+"," +year+ " is "+numDays);
how to make the month instead of numbers become words like if u input 1 becomes january. 2 =februaryComment
-
Why don't you store months in an array or arraylist? Then you would do months[index] and it would call the correct month?Originally posted by shadachiin the switch statement rite?
i put
the output i got. is the number of days in 1,2006 is 31.Code:switch(month){ case1: case3; case5; numdays=31; break; default: System.out.println("Invalid month."); break; } System.out.println("The Number of Days in " +month+"," +year+ " is "+numDays);
how to make the month instead of numbers become words like if u input 1 becomes january. 2 =februaryComment
-
If you have declared an array sayOriginally posted by shadachihow do u make them into arrays.. coz i am using switch statements.. can u giv an example?
Then if the user inputs 1 and you store it into an int variable called month, then you can doCode:String[] months = {"January", "February", ...};
[CODE=java]System.out.prin tln("Month entered is" + months[month -1 ]);[/CODE]
Do you understand that part?Comment
-
Well then you'll just have to learn them. Your initial problem description did not require you to express the month entered as a string so the switch stll solves the problem. If you want to show the name of the month entered then either use a dirty chunk of if-else statements or use the array.Originally posted by shadachinot quite but the declaring part i do.. the 2nd part not so clear.. coz i din learn anything bout arrays yetComment
-
... or a GregorianCalend ar object ...Originally posted by r035198xWell then you'll just have to learn them. Your initial problem description did not require you to express the month entered as a string so the switch stll solves the problem. If you want to show the name of the month entered then either use a dirty chunk of if-else statements or use the array.
kind regards,
JosComment
Comment