Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Toenglish{
- public static void main(String[] args){
- int x = Integer.parseInt(args[0]);
- int d = (args[0]).length();
- String Units,Tens,Hundreth,Thousand,TenThousand, HundredThousand;
- Units = " ";
- Tens = " ";
- Hundreth = " ";
- Thousand = " ";
- TenThousand = " ";
- HundredThousand = " ";
- String full = "";
- String[] units = {
- "",
- " one",
- " two",
- " three",
- " four",
- " five",
- " six",
- " seven",
- " eight",
- " nine",
- " ten",
- " eleven",
- " twelve",
- " thirteen",
- " fourteen",
- " fifteen",
- " sixteen",
- " seventeen",
- " eighteen",
- " nineteen"
- };
- String[] tensNames = {
- "",
- " ten",
- " twenty",
- " thirty",
- " forty",
- " fifty",
- " sixty",
- " seventy",
- " eighty",
- " ninety"
- };
- while(x>=0){
- if(x%100>0 && x%100<20){ // 0-20
- Units += units[x%100];
- System.out.print(units[x%20]);
- x/=100;}
- else{
- Tens += tensNames[(x%100)/10];
- x = x%10;}
- if(x/100<10){
- Hundreth += units[x/100] + " Hundred";
- x = x%100;}
- if(x/1000>0 && x/1000<20){
- Thousand += units[x/1000] + " Thousand";
- x = x%1000;}
- if(x/10000>20 && x/10000<100){
- TenThousand += tensNames[x/10000];
- x = x%10000;}
- if(x/100000<10){
- HundredThousand += units[x/100000]+ " Hundred";
- x = x%100000;}
- }
- System.out.println(HundredThousand + TenThousand + Thousand + Hundreth + Tens + Units);
- }
- }
Add Comment
Please, Sign In to add comment