A simple program in Java that will ask the user to give a number in integer format and then the program will convert the given decimal number into roman numeral equivalent.
I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360.
Thank you very much and Happy Programming.
Sample Program Output
Program Listing
// decimal_romans.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date : July 19, 2015
// Tools : Netbeans 8.0.2
// Email : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
import java.util.Scanner;
class decimal_romans
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
char ch;
do {
String thousands[]={"","M","MM","MMM","MMMM"};
String hundreds[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String tens[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String units[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
System.out.println();
System.out.print("\t NUMBER TO ROMAN NUMERALS ");
System.out.println("\n");
System.out.print("Enter a Number : ");
int number = input.nextInt();
if(number>0 && number<5000)
{
int th=number/1000;
int h=(number/100)%10;
int t=(number/10)%10;
int u=number%10;
System.out.println("Roman Equivalent= "+thousands[th]+hundreds[h]+tens[t]+units[u]);
}
else
System.out.println("nYou entered a number out of Range."
+ "Please enter a number in the range [1-4999] only");
System.out.print("\nDo you want to continue (Type y or n) : ");
ch = input.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
System.out.println();
System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
System.out.println("\n\n");
}
}