Originally posted by r035198x
CAn anyone help me wit the?? scanner stdin?
Collapse
X
-
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
-
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
-
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
-
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
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
-
Originally posted by shadachiin the switch statement rite?
i put
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
-
Originally posted by shadachihow do u make them into arrays.. coz i am using switch statements.. can u giv an example?
Code:String[] months = {"January", "February", ...};
[CODE=java]System.out.prin tln("Month entered is" + months[month -1 ]);[/CODE]
Do you understand that part?Comment
-
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
-
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