How does it work with Strings? For example, enter words like "one", "two", or "three" and returns integers 1, 2, or 3.
Printable View
How does it work with Strings? For example, enter words like "one", "two", or "three" and returns integers 1, 2, or 3.
With java version 1.7 you could use a switch statement.
With Older versions could use a Map or a chain of if/else if statements
Or an array with a loop
or some other method.
I know the switch case for int -> words, but how do you do it the other way around?
With version 1.7:
case "one":
case "one": return 1;
Is it?
What follows the case has not changed. The programmer can put anything there.
So I can put
case "January": return 1;
?
If you have the 1.7 JDK, try it and see what happens.