Skip to content

Instantly share code, notes, and snippets.

@bkawk
Created February 10, 2019 10:07
Show Gist options
  • Save bkawk/bd641a999310b763c8a3391f49bffa1f to your computer and use it in GitHub Desktop.
Save bkawk/bd641a999310b763c8a3391f49bffa1f to your computer and use it in GitHub Desktop.
public class numberToString {
public static void main(String[] args) {
int input = 50 ;
String undred = "undred";
String[] endNumbers = {"", "one", "two", "three","four", "five", "six", "seven", "eight", "nine", "ten"};
String[] weirdTeens = {"", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
String[] overTwenty = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
if (input <= 10) System.out.println(input + " " + endNumbers[input]);
if (input > 10 && input < 20) System.out.println(input + " " + weirdTeens[input - 10]);
if (input > 15) {
String test = Integer.toString(input);
String StringArray[] = test.split("\\B");
int IntegreArray[] = new int[StringArray.length];
for (int i = 0; i < StringArray.length; i++) {
IntegreArray[i] = Integer.parseInt(StringArray[i]);
if (IntegreArray.length < 3) { System.out.print(input + " " + overTwenty[IntegreArray[0]] + endNumbers[IntegreArray[1]]);} else System.out.print(input + " " + undred);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment