Question: Can a expert teach me? I am writing a program that asks a user to enter any number and it turns it into a roman
Can a expert teach me?
I am writing a program that asks a user to enter any number and it turns it into a roman numeral
Example:
This is how it should work
Enter an Integer: 342 (Could be any number user puts in)
Roman Numeral: CCCXLII
this is what I have in my program can you explain how I can return roman from the arabicToRoman method and have my program work?
import java.util.Scanner;
public class ArabicToRomanNumerals {
static Scanner input = new Scanner(System.in);
static int userInput;
static int quit = -1;
public static void main(String[] args) {
// Repeats question until users enters -1 to quit
do {
System.out.print("Enter an integer (-1 to quit): ");
userInput = input.nextInt();
System.out.print("Roman Numeral: ");
if (userInput 3999) {
System.out.print("The Romans did not have a way to represent negative numbers or zeros ");
System.out.print("Enter a valid number: ");
userInput = input.nextInt();
} else if (userInput == quit) {
System.out.print("Goodbye!");
}
} while (userInput != quit);
}
public static String arabicToRoman(int arabic) {
String roman = ""; // string for roman numerals
// array of numbers and calculations
int[] numbers = new int[7];
numbers[0] = arabic / 1000; // Calculation for M
numbers[1] = arabic % 1000 / 500; // Calculation for D
numbers[2] = arabic % 500 / 100; // Calculation for C
numbers[3] = arabic % 100 / 50; // Calculation for L
numbers[4] = arabic % 50 / 10; // Calculation for X
numbers[5] = arabic % 10 / 5; // Calculation for V
numbers[6] = arabic % 5; // Calculation for I
// Roman Numerals String
String[] romanNumerals = new String[] { "M", "D", "C", "L", "X", "V", "I" };
for (int i = 0; i
int number = numbers[i];
if (number == 4) {
roman = roman.substring(0, roman.length() - 1) + romanNumerals[i] + romanNumerals[i - 2];
} else {
for (int index = 0; index
roman += romanNumerals[i];
}
}
}
return roman;
}
}
These are instructions



\f\f\f
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
