Skip to content

aykofx/IntegerToRoman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Roman Numeral Converter

A simple Java program that converts an integer into its Roman numeral representation.

πŸ“Œ Description

This program takes a decimal (base-10) number as input from the user and converts it to its equivalent Roman numeral using a straightforward greedy algorithm.

Example

Input: 1987

Output: MCMLXXXVII

πŸ’‘ How It Works

The program uses two arrays:

  • numbers[] contains decimal values in descending order.
  • roman[] contains corresponding Roman numeral strings.

It iteratively subtracts the largest possible Roman value and appends the Roman numeral until the entire number is converted.

🧠 Core Logic

for (int i = 0; i < numbers.length; i++) {
    while (userInput >= numbers[i]) {
        userInput = userInput - numbers[i];
        sb.append(roman[i]);
    }
}

About

Program that converts numbers into Roman numerals using efficient logic.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages