Advertisement
Guest User

Exercise Four-Two

a guest
Sep 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1.  
  2. public class NumberToWords {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.         String input = args[0];
  7.         String output = "";
  8.        
  9.         int index = 0;
  10.         while(index < 3) {
  11.             switch(input.charAt(index)) {
  12.             case '1':
  13.                 output = output + "One ";
  14.                 break;
  15.             case '2':
  16.                 output = output + "Two ";
  17.                 break;
  18.             case '3':
  19.                 output = output + "Three ";
  20.                 break;
  21.             case '4':
  22.                 output = output + "Four ";
  23.                 break;
  24.             case '5':
  25.                 output = output + "Five ";
  26.                 break;
  27.             case '6':
  28.                 output = output + "Six ";
  29.                 break;
  30.             case '7':
  31.                 output = output + "Seven ";
  32.                 break;
  33.             case '8':
  34.                 output = output + "Eight ";
  35.                 break;
  36.             case '9':
  37.                 output = output + "Nine ";
  38.                 break;
  39.             case '0':
  40.                 output = output + "Zero ";
  41.                 break;
  42.             }
  43.            
  44.             index++;
  45.         }
  46.  
  47.         System.out.println(output);
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement