19+ Java Decimal to Roman Converters

This post contains a total of 19+ Hand-Picked Java Decimal to Roman Converter examples with Source Code. All the Decimal to Roman Converters are made using Java Programming langauge.

You can use the source codes of these programs for educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Nazar Shved

Made by Nazar Shved. This Java program Converts your decimal number into Roman numbers. ( Source )

import java.util.*;

public class Program
{
    public static void main(String[] args) {
    
    Scanner in = new Scanner(System.in);

		
  int inp = in.nextInt();
  
  System.out.println("Your input is: " + inp);

		String res = "";

		int[] dec = {1, 5, 10, 50, 100, 500, 1000};

		String[] rom = {"I", "V", "X", "L", "C", "D", "M"};

		int temp = inp;

		int tens = 1;

		int[] spliter = new int[4];


		for(int i = spliter.length-1; i >= 0 ; i--) {

			spliter[i] = temp % 10 * tens;

			tens *= 10;

			temp /= 10;

		}

		int sCount = 0;

		

		for(int i = dec.length-1;i >= 0; i--) {

			if(sCount == spliter.length) break;

			

			for(int j = 0; j < i; j +=2){

				if(spliter[sCount] == dec[i] - dec[j]) {

					res += rom[j] + rom[i];

					spliter[sCount] -= dec[i] - dec[j];

					break;

				}

			}

			while(spliter[sCount] >= dec[i]) {

				res += rom[i];

				spliter[sCount] -= dec[i];

			}

   if(spliter[sCount] == 0) {

				sCount++;

				i = dec.length;

			}
	}
System.out.println("Your number in Roman: " + res + "\n");

//System.out.println("")

 }
}

2. By Evgeniy Druzhkov

Made by Evgeniy Druzhkov. ( Source )


public class Programm
 {

    public static void main(String[] args) {
        System.out.println(decimal2Roman(34));
        System.out.println(roman2Decimal("XXXIV"));
    }

    public static String decimal2Roman(int dec) {
        String[] romanCharacters = {"C", "XC", "L", "X", "IX", "V", "I"};
        int[] romanValues = {100, 90, 50, 10, 9, 5, 1};
        String result = "";

        for (int i = 0; i < romanValues.length; i++) {
            int numberInPlace = dec / romanValues[i];
            if (numberInPlace == 0) {
                continue;
            }
            result = numberInPlace == 4 && i > 0
                    ? result + romanCharacters[i] + romanCharacters[i - 1]
                    : result + new String(new char[numberInPlace]).replace("\0", romanCharacters[i]);
            dec = dec % romanValues[i];
        }
        return result;
    }

    public static int roman2Decimal(String roman) {
        char[] arrayRoman = roman.toCharArray();
        int lengthArray = arrayRoman.length;
        int[] arrayDecimal = new int[lengthArray];
        int maxValue = 0;
        int indexerMaxValue = 0;
        int result = 0;
        for (int i = 0; i < lengthArray; i++) {
            int tmp;
            switch (arrayRoman[i]) {
                case 'I':
                    tmp = 1;
                    break;
                case 'V':
                    tmp = 5;
                    break;
                case 'X':
                    tmp = 10;
                    break;
                case 'L':
                    tmp = 50;
                    break;
                case 'C':
                    tmp = 100;
                    break;
                default:
                    return 0;
            }
            arrayDecimal[i] = tmp;
            if (tmp > maxValue) {
                maxValue = tmp;
                indexerMaxValue = i;
            }
        }
        for (int j = 0; j < lengthArray; j++) {
            if (j < indexerMaxValue) {
                result = result - arrayDecimal[j];
            } else {
                result = (j == lengthArray - 1 || arrayDecimal[j] >= arrayDecimal[j + 1])
                        ? result + arrayDecimal[j]
                        : result - arrayDecimal[j];
            }
        }
        return result;
    }
}

3. By Marco Bongini

Made by Marco Bongini. A simple decimal to roman converter program. ( Source )

import java.util.Scanner;

public class Program
{
    private static final String[] roman = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
	private	static final int[] decimal = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
	private static String result = "";
	
	protected static void convertToRoman(int num){
	    for(int i = 0; i < decimal.length; i++){
		    while(num % decimal[i] < num){
		        result += roman[i];
		        num -= decimal[i];
		    }
		}
	}
	
	public static void main(String[] args) {
	    int number = new Scanner(System.in).nextInt();
	    
	    convertToRoman(number);
		System.out.println(result);
    }
}

4. By Areesh Zafar

Made by Areesh Zafar. ( Source )



import java.util.Scanner;

public class DecimalToRoman
{
     
    
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int number = s.nextInt();
        String roman="";
        while(number>=1000){
            number-=1000;
            roman+="M";
        }
        while(number>=500){
            number-=500;
            roman+="D";
        }
        while(number>=100){
            number-=100;
            roman+="C";
        }
        while(number>=50){
            number-=50;
            roman+="L";
        }
        while(number>=10){
            number-=10;
            roman+="X";
        }
        while(number==9){
            number-=9;
            roman+="IX";
        }
        while(number>=5){
            number-=5;
            roman+="V";
        }
        if(number==4){
            number-=4;
            roman+="IV";
        }
        while(number>=1){
            number-=1;
            roman+="I";
        }
        System.out.println(roman);
    }
}

5. By Chintu

Made by Chintu. ( Source )

import java.io.*;

class DecimalToRoman {

static String toRoman(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) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter a number : ");

int decimal = Integer.parseInt(br.readLine());

System.out.println(toRoman(decimal));

}

}

6. By Ifshaul Haque

Made by Ifshaul Haque. ( Source )

import java.util.Scanner;

public class Program
{
    public static void main(String[] args) {
        System.out.println("Enter any number : ");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String roman="";
        String[] romanSymbol={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
        int[] symbolValue={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        
        for(int i=0;i<romanSymbol.length;i++) {
            while(n/symbolValue[i]!=0) {
                n = n-symbolValue[i];
                roman=roman+romanSymbol[i];
            }
        }
        System.out.print(roman);
    }
}

7. By John McDonald

Made by John McDonald. Program converts Decimal to Roman .You can use digits upto 3999. But it can be easily be extended to use higher digits by editing line 10. ( Source )

import java.util.Scanner;
class Program
{public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int a =input.nextInt();String roman="";
        final char b[]={'M','D','C','L','X','V','I','I'};
        final int c[]={1000,500,100,50,10,5,1,1};
        int d =0;int e=0;
        if(a<3999){
        while (a>1000){roman=roman+b[0];a=a-1000;}
       while(a>0){if(c[d]>a&&e<1){d++;}
                 else if(c[d]>a&&e>0){roman = roman +calculate(e,d);e=0;d=d+1;}
                 else{ a=a-c[d];e=e+1;}}
        roman=roman+calculate(e,d);
        System.out.println(roman);}
        else{System.out.println("The number is too large.");}}
public static String calculate(int a,int b)
    {String s="";final char z[]={'M','D','C','L','X','V','I'};
        switch(a){case 1:s=s+z[b];break;
            case 2:s=s+z[b]+z[b];break;
            case 3:s=s+z[b]+z[b]+z[b];break;
            case 4:s=s+z[b]+z[b-1];break;}
            return s;}}

8. By Prantik Sarkar

Made by Prantik Sarkar. ( Source )

import java.io.*;
class DecToRoman
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int num;
    String str="";
System.out.println("Enter a Number : ");
num=Integer.parseInt(br.readLine()); //accepting decimal number
System.out.println("Entered: "+num);
    /*Arrays storing the unique symbols of Roman Number System and also the corresponding decimal equivalents in the second array*/
 String roman[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int decimal[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
    if(num>0 && num<4000) //checking whether the number entered is within the range &#91;1-3999&#93;
        {
    for (int i=0; i<13; i++) // i<13 because the total unique numbers stored in the above array=13
       {
 /*The while loop is for printing repeated digits like XXX for 30 etc and is also calculating the equivalent Roman number by adding the corresponding Roman Digits from the Array to the String str*/
        while (num >= decimal[i])
           {
            num = num-decimal[i];
            str = str+roman[i];
            }
             }
 System.out.println("Roman Equivalent = "+str); //Printing the Roman equivalent
        }
        /*Displaying an error message if the number entered is out of range*/
        else
 System.out.println("nYou entered a number out of Range.nPlease enter a number in the range [1-3999]");
}
}//end of class

9. By waayne

Made by waayne. ( Source )

import java.util.Scanner;

public class DecimalToRoman
{
    private static String roman = "";
    private static int number = 0;
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        number = s.nextInt();
        while(number>=1000){
            number-=1000;
            roman+="M";
        }
        while(number>=500){
            number-=500;
            roman+="D";
        }
        while(number>=100){
            number-=100;
            roman+="C";
        }
        while(number>=50){
            number-=50;
            roman+="L";
        }
        while(number>=10){
            number-=10;
            roman+="X";
        }
        while(number==9){
            number-=9;
            roman+="IX";
        }
        while(number>=5){
            number-=5;
            roman+="V";
        }
        if(number==4){
            number-=4;
            roman+="IV";
        }
        while(number>=1){
            number-=1;
            roman+="I";
        }
        System.out.println(roman);
    }
}

10. By hasan almahamad

Made by hasan almahamad. ( Source )

/*
convert decimal number to roman number

M = 1000
D = 500
C = 100 
L = 50
X = 10
V = 5
I = 1
*/
import java.util.*;
public class Program
{
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
        int number = scan.nextInt();
        toRoman(number);
    }
    public static void toRoman (int number){
    List<Character> c = new ArrayList<>();
        if(number <= 0){
            System.out.println("Wrong");
        }
        while(number != 0){
            if(number >= 1000){
                putDigit('M',number/1000,c);
                number %=1000;
            }else if(number >= 500){
                if(number < 900){
                    putDigit('D',number/500,c);
                    number %=500;   
                }else{
                    subDigit('C','M',c);
                    number -= 900;
                }
            }else if(number >= 100){
                if(number < 400){
                    putDigit('C',number/100,c);
                    number %=100;
                }else{
                    subDigit('C','D',c);
                    number -= 400;
                }
            }else if(number >= 50){
                if(number < 90){
                    putDigit('L',number/50,c);
                    number %=50;
                }else{
                    subDigit('X','C',c);
                    number -=90;
                }
            }else if(number >= 10){
                if(number < 40){
                    putDigit('X',number/10,c);
                    number %=10;
                }else{
                    subDigit('X','L',c);
                    number -=40;
                }
            }else if(number >= 5){
                if(number < 9){
                    putDigit('V',number/5,c);
                    number %=5;
                }else{
                    subDigit('I','X',c);
                    number -= 9;
                }    
            }else{
                if(number < 4){
                    putDigit('I',number,c);
                    number %=1;
                }else{
                    subDigit('I','V',c);
                    number -=4;
                }
            }        
        }
        String str = "";
        for(char ch : c){
            str += ch;
        }
        System.out.println(str);
    }
    public static void putDigit(char n ,int num ,List c){
        for (int y = 0 ; y < num ;y++){
            c.add(n);
        }
    }
    public static void subDigit (char n1 ,char n2 ,List c){
        c.add(n1);
        c.add(n2);
    }
}

11. By Jay Prakash Mahto

Made by Jay Prakash Mahto. ( Source )

import java.util.*;
public class Decimal2Roman
	{
		static Scanner in=new Scanner(System.in);
		public static void main(String jvj[])
			{	
				maincopy();
			}

		static void maincopy()
			{
				int n;
				n = toAccept();
				toRoman(n);

				retry();
			}

		static int toAccept()
			{
				int n=0,ch=1;
				while (ch == 1)
					{
						try
							{
								System.out.println("Enter N");
								n = in.nextInt();
								ch = 0;
							}         //try ends
						catch (InputMismatchException e)
							{
								System.out.println("Error");
								System.out.println("Enter Again");
								in.nextLine(); //dummy scanner
							}  	//catch ends
					}       //loop ends
				return n;
			}
			
			static void toRoman(int no)
			{
				String noInString=Integer.toString(no);
	            String[] ones={"","I","II","III","IV","V","VI","VII","VIII","IX"};
				String[] tens={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
				String[] hundreds={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
				String[] thousands={"","M","MM","MMM"};
				
				if(no<0)
				    System.out.println("Negative No.s Are Not Allowed");
				else if(no<10)
				{
					if(no==0)
					{
						System.out.println("Sorry,Its Zero (0)");
						retry();
					}
					else
						System.out.println(ones[no]);
				}
				else if(no<100)
				{
					String tensPlaceDigitChar=""+noInString.charAt(0);
					int tensPlaceDigit=Integer.parseInt(tensPlaceDigitChar);
					String onesPlaceDigitChar=""+noInString.charAt(1);
					int onesPlaceDigit=Integer.parseInt(onesPlaceDigitChar);
			
					System.out.println(tens[tensPlaceDigit]+""+ones[onesPlaceDigit]);
				}
				else if(no<1000)
				{
					String hundredPlaceDigitChar=""+noInString.charAt(00);
					int hundredsPlaceDigit=Integer.parseInt(hundredPlaceDigitChar);
					String tensPlaceDigitChar=""+noInString.charAt(01);
					int tensPlaceDigit=Integer.parseInt(tensPlaceDigitChar);
					String onesPlaceDigitChar=""+noInString.charAt(02);
					int onesPlaceDigit=Integer.parseInt(onesPlaceDigitChar);

					System.out.println(hundreds[hundredsPlaceDigit]+""+tens[tensPlaceDigit]+""+ones[onesPlaceDigit]);
				}
				else if(no<4000)
				{
					String thousandPlaceDigitChar=""+noInString.charAt(00);
					int thousandPlaceDigit=Integer.parseInt(thousandPlaceDigitChar);
					String hundredPlaceDigitChar=""+noInString.charAt(01);
					int hundredsPlaceDigit=Integer.parseInt(hundredPlaceDigitChar);
					String tensPlaceDigitChar=""+noInString.charAt(02);
					int tensPlaceDigit=Integer.parseInt(tensPlaceDigitChar);
					String onesPlaceDigitChar=""+noInString.charAt(03);
					int onesPlaceDigit=Integer.parseInt(onesPlaceDigitChar);

					System.out.println(thousands[thousandPlaceDigit]+""+hundreds[hundredsPlaceDigit]+""+tens[tensPlaceDigit]+""+ones[onesPlaceDigit]);
				}
				else
					System.out.println("Its too Large No. Plz enter no. below 4000");
						
			}

		static void retry() 	//asking user if he wanted to replay than run program once again
			{
				System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
				System.out.println("Do you want to replay, \n Press Y/N");
				char confirm=in.next().charAt(0);
				System.out.println("______________________________________");	//ending 1st program
				if (confirm == 'Y' || confirm == 'y')
					maincopy();
				else
					System.exit(0);
			}
	}

12. By Artem Kharkov

Made by Artem Kharkov. ( Source )

public class DecimalAndRoman {
	public static void main(String[] args) {
		for (int i = 1; i <= 20; i++) {
			System.out.println(i + " ====> " + decimal2Roman(i) +
					" ====> " + roman2Decimal(decimal2Roman(i)));
		}
		System.out.println("...");
		for (int i = 94; i <= 100; i++) {
			System.out.println(i + " ====> " + decimal2Roman(i) +
					" ====> " + roman2Decimal(decimal2Roman(i)));
		}
	}

	public static String decimal2Roman(int x) {
		String[] rom = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C" };
		int[] value = { 1, 4, 5, 9, 10, 40, 50, 90, 100 };
		StringBuilder str = new StringBuilder();
		int i = value.length - 1;
		while (x > 0) {
			while (value[i] > x) {
				i--;
			}
			str.append(rom[i]);
			x -= value[i];
		}
		return str.toString();
	}

	public static int roman2Decimal(String s) {
		char[] rom = { 'I', 'V', 'X', 'L', 'C' };
		int[] value = { 1, 5, 10, 50, 100 };
		int result = 0;
		for (int j = 0; j < rom.length; j++) {
			if (s.charAt(s.length() - 1) == rom[j]) {
				result += value[j];
				break;
			}
		}
		int tmp = result;
		if (s.length() > 1) {
			for (int i = s.length() - 2; i >= 0; i--) {
				for (int j = 0; j < rom.length - 1; j++) {
					if (s.charAt(i) == rom[j]) {
						if (value[j] < tmp) {
							result -= value[j];
							tmp = value[j];
						} else {
							result += value[j];
						}
						break;
					}
				}
			}
			if (s.charAt(0) == 'X' && s.charAt(1) == 'L' && result > 60) {
				result -= 20;
			}
			if (s.charAt(0) == 'X' && s.charAt(1) == 'C' && result < 90) {
				result += 80;
			}
		}
		return result;
	}
}

13. By LukArToDo

Made by LukArToDo. A small java decimal to roman converter program. ( Source )

import java.util.*;
public class DecimalToRoman{
public static void main(String[] ar) {
    int input=new Scanner(System.in). nextInt();
    System.out.println(input>0&&input <4000?input+" ==  "+String.join("", Collections.nCopies(input,"I")).replace("IIIII","V").replace("IIII","IV").replace("VV","X").replace("VIV","IX").replace("XXXXX","L").replace("XXXX","XL").replace("LL","C").replace("LXL","XC").replace("CCCCC","D").replace("CCCC","CD").replace("DD","M").replace("DCD", "CM"):"Your input is out of given range [1-3999] ");
    }
}

14. By Antonio Avella

Made by Antonio Avella. ( Source )

import java.util.*;

public class romani {

	public static void main(String args[]) {
	int input = new Scanner(System.in).nextInt();
		int c;
		int i;
		int j;
		String output="";
		
		int[] a = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
	
		String[] b = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
	
		for (i=12;i>=0;i--) {
		     j =(input/a[i]);
			
			for (c=1;c<=j;c++) {
				output = output+b[i];
				input = input-a[i];
			}
			
		}
		
		System.out.println(output);
	}


}

15. By Aldo Alexandro Vargas Meza

Made by Aldo Alexandro Vargas Meza. The decimal input number should be between 0 – 999. ( Source )

import java.util.Scanner;

public class Program {

	static int numero, tamanio, unidades, decenas, centenas, uni_millar, dec_millar, cen_millar;
	static Scanner in = new Scanner(System.in);
	static String uni_romano, dec_romano, cen_romano;

public static int unidades(int numero){
	int unidad = (numero%100)%10;
	
	return unidad;
}
public static String uni_romano(int unidades){
	String uni_romano;
	switch(unidades){
		case 0: uni_romano = " ";
		break;
		case 1: uni_romano = "l";
		break;
		case 2: uni_romano = "ll";
		break;
		case 3: uni_romano = "lll";
		break;
		case 4: uni_romano = "lV";
		break;
		case 5: uni_romano = "V";
		break;
		case 6: uni_romano = "Vl";
		break;
		case 7: uni_romano = "Vll";
		break;
		case 8: uni_romano = "Vlll";
		break;
		case 9: uni_romano = "lX";
		break;
		default: uni_romano="";
		break;
	}
	
	return uni_romano;
}


public static int decenas(int numero){
	int decena = (numero%100)/10;
	
	return decena;
}
public static String dec_romano(int decenas){
	String dec_romano;

	switch (decenas){
		case 1: dec_romano = "X";
		break;
		case 2: dec_romano = "XX";
		break;
		case 3: dec_romano = "XXX";
		break;
		case 4: dec_romano = "lX";
		break;
		case 5: dec_romano = "L";
		break;
		case 6: dec_romano = "LX";
		break;
		case 7: dec_romano = "LXX";
		break;
		case 8: dec_romano = "LXXX";
		break;
		case 9: dec_romano = "XC";
		break;
		default: dec_romano ="";
	}
	
	return dec_romano;
}

public static int centenas(int numero){
	int centena = numero/100;
	
	return centena;
}
public static String cen_romano(int centenas){
	String cen_romanos;
	
	switch(centenas){
		case 1: cen_romanos = "C";
		break;
		case 2: cen_romanos = "CC";
		break;
		case 3: cen_romanos = "CCC";
		break;
		case 4: cen_romanos = "CD";
		break;
		case 5: cen_romanos = "D";
		break; 
		case 6: cen_romanos = "DC";
		break;
		case 7: cen_romanos = "DCC";
		break;
		case 8: cen_romanos = "DCCC";
		break;
		case 9: cen_romanos = "CM";
		break;
		default: cen_romanos ="";
	
	}
	
	return cen_romanos;
}

	
	public static void main(String[] args) {
		
			numero = in.nextInt();
			tamanio = String.valueOf(numero).length();
			unidades = unidades(numero);
			decenas = decenas(numero);
			centenas = centenas(numero);
			uni_romano = uni_romano(unidades);
			dec_romano = dec_romano(decenas);
			cen_romano = cen_romano(centenas);
		
		
		System.out.println(cen_romano + dec_romano + uni_romano + " ");
 		
	}

}

16. By anas khan

Made by anas khan. ( Source )

import java.util.*;

class Roman{
    public static String IntegerToRoman(int n){
        String roman="";
        int repeat;
 
        repeat=n/1000;
        for(int i=1; i<=repeat;i++){
            roman=roman+"M";
        }
        n=n%1000;
 
        repeat=n/900;
        for(int i=1; i<=repeat;i++){
            roman=roman+"CM";
        }
        n=n%900;
 
        repeat=n/500;
        for(int i=1; i<=repeat;i++){
            roman=roman+"D";
        }
        n=n%500;
 
        repeat=n/400;
        for(int i=1; i<=repeat;i++){
            roman=roman+"CD";
        }
        n=n%400;
 
        repeat=n/100;
        for(int i=1; i<=repeat;i++){
            roman=roman+"C";
        }
        n=n%100;
 
        repeat=n/90;
        for(int i=1; i<=repeat;i++){
            roman=roman+"XC";
        }
        n=n%90;
 
        repeat=n/50;
        for(int i=1; i<=repeat;i++){
            roman=roman+"L";
        }
        n=n%50;
 
        repeat=n/40;
        for(int i=1; i<=repeat;i++){
            roman=roman+"XL";
        }
        n=n%40;
 
        repeat=n/10;
        for(int i=1; i<=repeat;i++){
            roman=roman+"X";
        }
        n=n%10;
 
        repeat=n/9;
        for(int i=1; i<=repeat;i++){
            roman=roman+"IX";
        }
        n=n%9;
 
        repeat=n/5;
        for(int i=1; i<=repeat;i++){
            roman=roman+"V";
        }
        n=n%5;
 
        repeat=n/4; 
        for(int i=1; i<=repeat;i++){
            roman=roman+"IV";
        }
        n=n%4;
 
         repeat=n/1;
        for(int i=1; i<=repeat;i++){
            roman=roman+"I";
        }
        return roman;
    }
    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);
        int num =sc.nextInt();
        System.out.println(num+" "+IntegerToRoman(num));
    
    }
}

17. C. Scheler

Made by C. Scheler. Run and enter an integer number to get a roman output! If you don’t enter an integer, you’ll get a random number between -3000 and 3000. ( Source )

import java.util.Scanner;
public class Program
{
    public static String dec_rom(int drin) {
        if(drin==0)
            return "There's no 0.";
        String drout = "";
        boolean negdrin = drin<0;
        if(negdrin)
            drin = -drin;
        for(int i=drin/1000; i>0; i--) {
            drout += "M";
        }
        drin %= 1000;
        int drc = drin/100;
        if(drc==9) {
            drout += "CM";
        } else if(drc==4) {
            drout += "CD";
        } else {
            for(int i=drin/500; i>0; i--) {
                drout += "D";
            }
            drin %= 500;
            for(int i=drin/100; i>0; i--) {
                drout += "C";
            }
        }
        drin %= 100;
        drc = drin/10;
        if(drc==9) {
            drout += "XC";
        } else if(drc==4) {
            drout += "XL";
        } else {
            for(int i=drin/50; i>0; i--) {
                drout += "L";
            }
            drin %= 50;
            for(int i=drin/10; i>0; i--) {
                drout += "X";
            }
        }
        drin %= 10;
        if(drin==9) {
            drout += "IX";
        } else if(drin==4) {
            drout += "IV";
        } else {
            for(int i=drin/5; i>0; i--) {
                drout += "V";
            }
            drin %= 5;
            for(int i=drin; i>0; i--) {
                drout += "I";
            }
        }
        if(negdrin)
            drout = "-" + drout;
        return drout;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input;
        try {
            input = sc.nextInt();
        } catch (Exception e) {
            System.out.println("Input an integer number!");
            //random number between -3000 and 3000
            input = (int) (Math.random()*6000);
            input -= 3000;
        }
        System.out.println(input + " = " + dec_rom(input));
    }
}

18. By Navjot-sondh

Made by Navjot-sondh. ( Source )

import java.util.Scanner;
class DecimalToRoman
{
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		int number,i;
		String[] romanNumerals={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M" };
		int[] decimalNumerals={1,4,5,9,10,40,50,90,100,400,500,900,1000};
		System.out.println("Enter a number");
		number=in.nextInt();
		while(number>0)
		{
			
			for(i=decimalNumerals.length-1;;i--)
			{
				if(decimalNumerals[i]<=number)
				{
					System.out.print(romanNumerals[i]);
					number=number-decimalNumerals[i];
					
					break;	
				}
				
			}
		}
	}
}

19. By Abu

Made by Abu. The romanizer function/method takes an int array as its argument returns a String array of the roman numerals of the numbers in the int array argument. ( Source )

/*
	AUTHOR: Samuel Abu
	Task: Converting Decimal Numbers to Roman Numerals

	PS: I was unable to complete the Task 7 in time. I think the timer is
	added pressure but what better way to test than to time us right?

	I figured it out a couple of minutes after the timer died(ran out).

*/

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Take2
{
    static String[] romanizer(int[] numbers) 
    {
        String [] result = new String[numbers.length];
        String roman = "";
        int res = 0;
        for(int i = 0; i < numbers.length; i++)
        {
            res = numbers[i];
			while(res > 999)
			{
				roman = roman + "M";
				res = res - 1000;
			}
			if(res > 899)
			{
				roman = roman + "CM";
				res = res - 900;
			}
			if(res > 499)
			{
				roman = roman + "D";
				res = res - 500;
			}
			if(res > 399)
			{
				roman = roman + "CD";
				res = res - 400;
			}
			while(res > 99)
			{
				roman = roman + "C";
				res = res - 100;
			}
			if(res > 89)
			{
				roman = roman + "XC";
				res = res - 90;
			}
			if(res > 49)
			{
				roman = roman + "L";
				res = res - 50;
			}
			if(res > 39)
			{
				roman = roman + "XL";
				res = res - 40;
			}
			while(res > 9)
			{
				roman = roman + "X";
				res = res - 10;
			}
			if(res > 8)
			{
				roman = roman + "IX";
				res = res - 9;
			}
			if(res > 4)
			{
				roman = roman + "V";
				res = res - 5;
			}
			if(res > 3)
			{
				roman = roman + "IV";
				res = res - 4;
			}
			while(res > 0)
			{
				roman = roman + "I";
				res = res - 1;
			}			             
	        result[i] = roman;
	        roman = "";
	        continue;
        }
        return result;
    }

    public static void main(String [] args)
    {
    	Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] ar = new int[n];
        for(int ar_i = 0; ar_i < n; ar_i++){
            ar[ar_i] = in.nextInt();
        }
        String [] finall = romanizer(ar);
        for(int i = 0; i < n; i++){
            System.out.println(finall[i]);
        }

    }
}

20. By Bruno A. Rolim

Made by Bruno A. Rolim. ( Source )

import java.util.HashMap;
import java.util.Map;


public class Roman {

	private static Map<Integer, String> numerals = new HashMap<Integer, String>();
	
	static {
		numerals.put(1, "I");
		numerals.put(2, "II");
		numerals.put(3, "III");
		numerals.put(4, "IV");
		numerals.put(5, "V");
		numerals.put(6, "VI");
		numerals.put(7, "VII");
		numerals.put(8, "VIII");
		numerals.put(9, "IX");
	}
	
	public static String convertUnit(Integer decimal){
		if(numerals.get(decimal) == null){
			return "";
		}
		
		return numerals.get(decimal);
	}
	
	public static String convertDecimalToRoman(Integer decimal) {
		
		String result = "";
		
		int dezenas = decimal/10;
		result = convertUnit(dezenas).replace("X", "C").replace("I", "X").replace("V", "L");
		result += convertUnit(decimal-dezenas*10);
		
		return result;
	}

}