[Tutor] Projects

Terry Carroll carroll at tjc.com
Wed Jan 23 20:33:50 CET 2008


On Wed, 23 Jan 2008, Jason Massey wrote:

> An example routine to translate a number into [its] english equivalent 
> was given (again, this is Java):
>   static String convertDigitToEnglish(int d)  {
>       switch ( d )
>       {
> 
>          case 1: return "one";
>          case 2: return "two";
>          case 3: return "three";
>          case 4: return "four";
>          case 5: return "five";
>          case 6: return "six";
>          case 7: return "seven";
>          case 8: return "eight";
>          case 9: return "nine";
>          default: return "\nFatal Error!\n"; // should I abort pgm?
>       } // end of switch
>   } // end of convertDigitToEnglish
> 
> In Python I'd just use a dictionary.

I'm no Java expert, but isn't Java's Map more or less equivalent to 
Python's dictionary?

http://java.sun.com/javase/6/docs/api/java/util/Map.html



More information about the Tutor mailing list