Categories
Java

Decimal To Roman Numeral in Java

Machine Problem in Java

Write a program to ask the user to give a number and then the program will convert the given number into Roman numeral equivalent.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following [email protected], [email protected], and [email protected]

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.

Program Listing

/**
Machine Problem in Java

Write a program to ask the user to give a number and then the 
program will convert the given number into Roman numeral 
equivalent.

 @author Jake Rodriguez Pomperada,MAED-IT, MIT
 www.jakerpomperada.com / www.jakerpomperada.blogspot.com
 [email protected]
 Bacolod City, Negros Occidental Philippines
 January 14, 2021 Thursday 8:58 PM
*/

import java.util.*;


public class Decimal_Roman_Numeral {

	private static String Convert_To_Roman_Numeral(int num) {
		String[] romanCharacters = { "M", "CM", "D", "C", "XC", "L", "X", "IX", "V", "I" };
		int[] romanValues = { 1000, 900, 500, 100, 90, 50, 10, 9, 5, 1 };
		String result = "";
		 
		for (int i = 0; i < romanValues.length; i++) {
		int numberInPlace = num / romanValues[i];
		if (numberInPlace == 0) continue;
		result += numberInPlace == 4 && i > 0? romanCharacters[i] + romanCharacters[i - 1]:
		new String(new char[numberInPlace]).replace("\0",romanCharacters[i]);
		num = num % romanValues[i];
		}
		return result;
		}
		 
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		 Scanner sc=new Scanner(System.in);
	        int num=0;
	        
	        System.out.println();  
		    System.out.println("\tDecimal To Roman Numeral in Java");
		    System.out.println();
	     
	        System.out.print("\tGive a Number : ");
	        num=sc.nextInt();
	     
	        System.out.println();
	        System.out.println("\tThe Decimal Value   : " + num);
	        System.out.println("\tRoman Numeral Value : "
	        		+ Convert_To_Roman_Numeral(num));
	        System.out.println();
	        System.out.println("\tEnd of Program");
	        System.out.println("\n");
	        sc.close();
	}

} // End of Code

Leave a Reply

Your email address will not be published. Required fields are marked *