Question

Write a Java program.

In the modern Roman system a number is also a sequence of Ms, Ds, Cs, Ls, Xs, Vs, and 1s. The symbols have to appear more or less in that order and the value of a number is obtained as before with one important exception: A symbol C, X, or I may precede a symbol of higher value, in which case the value of that symbol C, X, or I is taken to be negative. Write a Function that will convert a decimal number to a modern Roman numeral. Demo 999 Examples Decimal Classical Roman Modern Roman 4 IV VIll IX 91

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the java program to convert decimal number into modern roman equivalent :

DecimalToModernRoman.java :

import java.io.*;
class DecimalToModernRoman
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input a Decimal Number : ");
int n=Integer.parseInt(br.readLine()); //Input the decimal number

if(n>0 && n<4000) //Enter the number in range 1-3999
{

//Decimal numbers equivalent to roman numbers
String thousands[]={"","M","MM","MMM"};
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"};

int ts=n/1000;
int h=(n/100)%10;
int t=(n/10)%10;
int u=n%10;

// Print the roman equivalent
System.out.println("The modern roman equivalent of decimal number " +n );
System.out.println("is - " +thousands[ts]+hundreds[h]+tens[t]+units[u]);
}

//Error message
else
System.out.println("Entered number is out of Range.Enter in range of 1-3999");
}
}

Output:

Inputa The modern roman equivalent of decimal number 91 is-XCI BUILD SUCCESSFUL (total time: 4 seconds) 91 RAI

Input a Decimal Number 999 The modern roman equivalent of decimal number 999 isCMXCIX BUILD SUCCESSFUL (total time: 3 seconds

Add a comment
Know the answer?
Add Answer to:
Write a Java program. In the "modern Roman" system a number is also a sequence of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write up a detailed solution to the problem: Design a program to convert a Roman numeral...

    Write up a detailed solution to the problem: Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number. Here are the “letters” you need to know: Symbol =   Value I   = 1 V =   5 X =   10 L =   50 C =   100 D =   500 M   =...

  • (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....

    (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately....

  • Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its...

    Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its decimal number representation. Write a main program to test the function. Your function should have two arguments - the roman number as a string, and an error processing function. Write a helper function that will return the numeric value of each of the letters used in roman numbers. Then convert the string argument as follows look at the first two characters. If the first...

  • How do i write a program to read muliple files? i can read one but i...

    How do i write a program to read muliple files? i can read one but i need to read 10: 0.txt - 9.txt Here is the code for reading one but i need to read 10 text files and print the frequencies of all the letters a - z, upper and lowercase, in one take. here is the output i should get #include <stdio.h> #include <stdlib.h> #include <string.h> #include <omp.h> int main() { double start_time = omp_get_wtime(); char str[1000); int...

  • (IN C LANGUAGE) 4.33 (Roman-Numeral Equivalent of Decimal Values) Write a program that prints a table...

    (IN C LANGUAGE) 4.33 (Roman-Numeral Equivalent of Decimal Values) Write a program that prints a table of all the Roman-numeral equivalents of the decimal numbers in the range 1 to 100. Decimal→→Roman↵ -------→→-----↵ 1→→I↵ 2→→II↵ 3→→III↵ 4→→IV↵ 5→→V↵ 6→→VI↵ 7→→VII↵ 8→→VIII↵ 9→→IX↵ 10→→X↵ 11→→XI↵ 12→→XII↵ 13→→XIII↵ 14→→XIV↵ 15→→XV↵ 16→→XVI↵ 17→→XVII↵ 18→→XVIII↵ 19→→XIX↵ 20→→XX↵ 21→→XXI↵ 22→→XXII↵ 23→→XXIII↵ 24→→XXIV↵ 25→→XXV↵ 26→→XXVI↵ 27→→XXVII↵ 28→→XXVIII↵ 29→→XXIX↵ 30→→XXX↵ 31→→XXXI↵ 32→→XXXII↵ 33→→XXXIII↵ 34→→XXXIV↵ 35→→XXXV↵ 36→→XXXVI↵ 37→→XXXVII↵ 38→→XXXVIII↵ 39→→XXXIX↵ 40→→XL↵ 41→→XLI↵ 42→→XLII↵ 43→→XLIII↵ 44→→XLIV↵ 45→→XLV↵ 46→→XLVI↵ 47→→XLVII↵...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • 1 Overview For this assignment you are required to write a Java program that plays (n,...

    1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...

  • Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arg...

    Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arguments shall consist of the following 1. The width (in pixels) of the image, as a positive decimal integer 2. The height (in pixels) of the image, as a positive decimal integer 3. The minimum area (in pixels) that a triangle must have in order to be drawn,...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT