Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sterling9 {
- public static String[] ones = {"","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
- public static String[] teens = {"", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
- "nineteen"};
- public static String[] tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
- public static String[] hundreds = {"", "one hundred ", "two hundred ", "three hundred ", "four hundred ",
- "five hundred ", "six hundred ", "seven hundred ", "eight hundred ", "nine hundred "};
- public static String[] thousands = {"thousand ", "one thousand ", "two thousand ", "three thousand ", "four thousand ", "five thousand ",
- "six thousand ", "seven thousand ", "eight thousand ", "nine thousand "};
- public static String[] teenThousands = { "ten thousand ", "eleven thousand ", "twelve thousand ", "thirteen thousand ", "fourteen thousand ", "fifteen thousand ",
- "sixteen thousand ", "seventeen thousand ", "eighteen thousand ","nineteen thousand "};
- public static String[] tenThousands = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
- public static String[] hundredThousands = {"","one hundred ", "two hundred ", "three hundred ", "four hundred ",
- "five hundred ", "six hundred ", "seven hundred ", "eight hundred ", "nine hundred "};
- public static String[] million = {"one million"};
- public static String[][] allOfThem = {{}, {}, tens, hundreds, thousands, tenThousands, hundredThousands};
- public static void main(String[] args) {
- Random gen = new Random();
- for (int i = 1; i <= 999999; i++){
- countEm("" + i);
- }
- }
- public static void countEm(String jString) {
- int i = Integer.parseInt(jString);
- if (i >= 0 && i <= 10) {
- System.out.println(ones[i]);
- return;
- }
- else if (i >= 11 && i <= 19) {
- System.out.println(teens[Integer.parseInt(jString.substring(1,2))] );
- return;
- }
- else if (i >= 10000 && i < 20000) {
- System.out.print(teenThousands[Integer.parseInt(jString.substring(1,2))]);
- countEm(jString.substring(2));
- }
- else {
- System.out.print(allOfThem[jString.length()][Integer.parseInt(jString.substring(0,1))]);
- countEm(jString.substring(1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement