GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Conversions/IntegerToRoman.java at master · sfm1234/Java Expand file tree/ Copy pathIntegerToRoman.javaMore file actions 29 lines (22 loc) · 923 Bytes / Copy pathIntegerToRoman.javaFile metadata and controls29 lines (22 loc) · 923 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 package Conversions; public class IntegerToRoman { private static int[] allArabianRomanNumbers = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; private static String[] allRomanNumbers = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; public static String integerToRoman(int num) { if (num <= 0) { return ""; } StringBuilder builder = new StringBuilder(); for (int a = 0; a < allArabianRomanNumbers.length; a++) { int times = num / allArabianRomanNumbers[a]; for (int b = 0; b < times; b++) { builder.append(allRomanNumbers[a]); } num -= times * allArabianRomanNumbers[a]; } return builder.toString(); } public static void main(String[] args) { System.out.println(IntegerToRoman.integerToRoman(2131)); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |