Created
February 10, 2019 05:58
-
-
Save bkawk/60ba23f199250a89c995318eb8a561fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class numberToString { | |
public static void main(String[] args) { | |
int input = 20 ; | |
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) { | |
int[]digits = Integer.toString(input).chars().map(c -> c-'0').toArray(); | |
if (digits.length < 3) { System.out.print(input + " " + overTwenty[digits[0]] + endNumbers[digits[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
public class numberToString {
public static void main(String[] args) {
int input = 20 ;
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);
}
}
}
}