Skip to content

Roman numeral type, arithmetic and conversion implemented in Java

License

Notifications You must be signed in to change notification settings

sebastianzander/roman-numeral-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roman Numeral

This is a Java implementation of a Roman numeral class that supports parsing of Roman numeral strings, the conversion between Roman numeral string and Arabic decimal integer representation as well as basic arithmetic and comparison operations.

Here is a quick usage example:

import de.sebastianzander.romannumerals.RomanNumeral;

public class Application
{
    public void main(String[] args)
    {
        // construct from either a Roman numeral string or an Arabic decimal integer
        RomanNumeral a = new RomanNumeral(1987);
        RomanNumeral b = new RomanNumeral("XXXIV");
        RomanNumeral c = RomanNumeral.fromRomanNumeralString("IV");

        // calculate sum of two RomanNumeral objects
        RomanNumeral s = a.add(b);

        // calculate sum of Iterable of RomanNumeral objects
        RomanNumeral t = RomanNumeral.sum(Arrays.asList(a, b, c));

        System.out.printf("%s + %s = %s\n", a, b, s);
        System.out.printf("%d + %d = %d\n", a.arabicDecimal(), b.arabicDecimal(), s.arabicDecimal());
    }
}

The above example should create the following output:

MCMLXXXVII + XXXIV = MMXXI
1987 + 34 = 2021

About

Roman numeral type, arithmetic and conversion implemented in Java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages