Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package com.saxion.thymo.variables;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Roman_nums {
  6.  
  7. private static final int ROMAN_I = 1;
  8. private static final int ROMAN_V = 5;
  9. private static final int ROMAN_X = 10;
  10.  
  11. public void main() {
  12. Scanner scanner = new Scanner(System.in);
  13. System.out.println("Enter a number to convert:");
  14. int decimal = scanner.nextByte();
  15. String roman = "";
  16.  
  17. while (decimal > 0) {
  18. if (decimal > ROMAN_X || decimal < 1) {
  19. roman = "Please enter a number between 1 and 10";
  20. break;
  21. }
  22.  
  23. if (decimal >= ROMAN_X) {
  24. decimal -= ROMAN_X;
  25. roman = roman + "X";
  26. } else if (decimal == ROMAN_X - ROMAN_I) {
  27. decimal -= 9;
  28. roman = roman + "IX";
  29. } else if (decimal >= ROMAN_V && decimal < ROMAN_X) {
  30. decimal -= ROMAN_V;
  31. roman = roman + "V";
  32. } else if (decimal == ROMAN_V - ROMAN_I) {
  33. decimal -= 4;
  34. roman = roman + "IV";
  35. } else if (decimal >= ROMAN_I && decimal < ROMAN_V) {
  36. decimal -= ROMAN_I;
  37. roman = roman + "I";
  38. }
  39. }
  40. System.out.println(roman);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement