Advertisement
tzoonami

Untitled

Apr 1st, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1.  
  2. public class Sterling9 {
  3.     public static String[] ones = {"","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
  4.     public static String[] teens = {"", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
  5.         "nineteen"};
  6.     public static String[] tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  7.     public static String[] hundreds = {"", "one hundred ", "two hundred ", "three hundred ", "four hundred ",
  8.         "five hundred ", "six hundred ", "seven hundred ", "eight hundred ", "nine hundred "};
  9.     public static String[] thousands = {"thousand ", "one thousand ", "two thousand ", "three thousand ", "four thousand ", "five thousand ",
  10.         "six thousand ",    "seven thousand ", "eight thousand ", "nine thousand "};
  11.     public static String[] teenThousands = { "ten thousand ", "eleven thousand ", "twelve thousand ", "thirteen thousand ", "fourteen thousand ", "fifteen thousand ",
  12.         "sixteen thousand ", "seventeen thousand ", "eighteen thousand ","nineteen thousand "};
  13.     public static String[] tenThousands = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  14.     public static String[] hundredThousands = {"","one hundred ", "two hundred ", "three hundred ", "four hundred ",
  15.         "five hundred ", "six hundred ", "seven hundred ", "eight hundred ", "nine hundred "};
  16.     public static String[] million = {"one million"};
  17.     public static String[][] allOfThem = {{}, {}, tens, hundreds, thousands, tenThousands, hundredThousands};
  18.  
  19.     public static void main(String[] args) {
  20.         Random gen = new Random();
  21.        
  22.         for (int i = 1; i <= 999999; i++){
  23.             countEm("" + i);
  24.         }
  25.     }
  26.     public static void countEm(String jString) {
  27.         int i = Integer.parseInt(jString);
  28.         if (i >= 0 && i <= 10) {
  29.             System.out.println(ones[i]);
  30.             return;
  31.         }
  32.         else if (i >= 11 && i <= 19) {
  33.             System.out.println(teens[Integer.parseInt(jString.substring(1,2))] );
  34.             return;
  35.         }
  36.         else if (i >= 10000 && i < 20000) {
  37.             System.out.print(teenThousands[Integer.parseInt(jString.substring(1,2))]);
  38.             countEm(jString.substring(2));
  39.         }
  40.         else {
  41.             System.out.print(allOfThem[jString.length()][Integer.parseInt(jString.substring(0,1))]);
  42.             countEm(jString.substring(1));
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement