Skip to content

Instantly share code, notes, and snippets.

@chintamanand
Last active July 20, 2022 04:18
Show Gist options
  • Save chintamanand/fb1bc3d03cf89f90316701b87193bbf6 to your computer and use it in GitHub Desktop.
Save chintamanand/fb1bc3d03cf89f90316701b87193bbf6 to your computer and use it in GitHub Desktop.
package RomanNumberExample;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import static java.lang.System.in;
import static java.lang.System.out;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(in);
out.println("Waiting for Input Request - ");
int num = scan.nextInt();
out.println("Received Input is -- " + num);
String englishWords[] = {"Million", "Lakh", "Ten Thousand", "Thousand", "Hundred",
"Ninety", "Eighty", "Seventy", "Sixty", "Fifty", "Forty", "Thirty", "Twenty",
"Nineteen", "Eighteen", "Seventeen", "sixteen", "Fifteen", "Fourteen", "Thirteen", "Twelve", "Eleven",
"Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two", "One", ""
};
int numbers[] = {1000000, 100000, 10000, 1000, 100,
90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15,
14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
String result = "";
for (int index = 0; index < numbers.length; index++) {
while (num >= numbers[index]) {
num = num - numbers[index];
result = result.concat(" ").concat(englishWords[index]);
}
}
System.out.println("Final Result is -- " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment