Showing posts with label decimal to roman numeral in java. Show all posts
Showing posts with label decimal to roman numeral in java. Show all posts

Monday, June 12, 2017

Decimal To Roman Numeral Converter in Java

In this article I would like to share with you a simple program that will ask the user to give a year and then our program will convert the given year into roman numeral equivalent using Java. The code is very easy to understand and use. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

// Written By: Mr. Jake R. Pomperada, MAED-IT
// Date : June 12, 2017  Monday 2:41 PM
// Language: Java
// Place of Origin:  Mandaluyong City, Metro Manila Philippines.


package demo;


import java.util.Scanner;

class roman {
public int a;
public int num,th,h,t,u;
 
String thou[]={"","M","MM","MMM"};
String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};

public void setA(int a) {
this.a = a;
}

public int getA() {
return a;
}
public void displayResult(int num)
{
this.num = num;
th=num/1000;
h=(num/100)%10;
t=(num/10)%10;
u=num%10;
System.out.println();
System.out.println("The given is " + num + ".");
System.out.println();
System.out.println("The Roman Numeral  Equivalent is  "+thou[th]+hund[h]+ten[t]+unit[u] + ".");
System.out.println();
   System.out.print("\t END OF PROGRAM");
System.out.println();
}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
     roman val = new roman(); 
  
      System.out.println();
      System.out.println("Decimal To Roman Numeral Converter Using Getters and Setters");
      System.out.println();
      System.out.print("Enter first value : ");
      val.a = input.nextInt();
      
       val.setA(val.a);
   val.getA();

   val.displayResult(val.a);
   
       input.close();
}

}