Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.saxion.thymo.variables;
- import java.util.Scanner;
- public class Roman_nums {
- private static final int ROMAN_I = 1;
- private static final int ROMAN_V = 5;
- private static final int ROMAN_X = 10;
- public void main() {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter a number to convert:");
- int decimal = scanner.nextByte();
- String roman = "";
- while (decimal > 0) {
- if (decimal > ROMAN_X || decimal < 1) {
- roman = "Please enter a number between 1 and 10";
- break;
- }
- if (decimal >= ROMAN_X) {
- decimal -= ROMAN_X;
- roman = roman + "X";
- } else if (decimal == ROMAN_X - ROMAN_I) {
- decimal -= 9;
- roman = roman + "IX";
- } else if (decimal >= ROMAN_V && decimal < ROMAN_X) {
- decimal -= ROMAN_V;
- roman = roman + "V";
- } else if (decimal == ROMAN_V - ROMAN_I) {
- decimal -= 4;
- roman = roman + "IV";
- } else if (decimal >= ROMAN_I && decimal < ROMAN_V) {
- decimal -= ROMAN_I;
- roman = roman + "I";
- }
- }
- System.out.println(roman);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement