Created
June 28, 2017 13:25
-
-
Save nitishk72/3a379ede24c600c43493dde9480e2cc2 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* This program is written withoutout any exception handling means , I'm assuming that your input will be between 1 to 1000 | |
* @author Nitish Kumar Singh | |
*/ | |
public class Integer2Words { | |
public static void main(String args[]){ | |
int input = 586; | |
String a[] = {"ONE","TWO","THREE","FOUR", "FIVE","SIX", "SEVEN","EIGHT", "NINE"}; | |
String b[] = {"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN"}; | |
String c[] = {"TEN","TWENTY","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINTY","HUNDREAD"}; | |
String output = ""; | |
int hun = (input%1000)/100; | |
int ten = (input%100)/10; | |
int onc = (input%10)/1; | |
output = hun!=0?a[(hun-1)]+" HUNDREAD ":""; | |
if(ten<2 && ten>0){ | |
output+= b[onc-1]; | |
}else{ | |
output+= ten>=2?c[(ten-1)]+" ":""; | |
output+= onc!=0?a[(onc-1)]+" ":""; | |
} | |
System.out.println("Input\t:\t"+input); | |
System.out.println("Output\t:\t"+output+"ONLY"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Till 10000:
class Integer2Words {
}