title: Converting Integers to Roman Numerals - Java
body: <p>This is a homework assignment I am having trouble with.</p>
  
  <p>I need to make an integer to Roman Numeral converter using a method. Later, I must then use the program to write out 1 to 3999 in Roman numerals, so hardcoding is out. My code below is very bare-bones; it is a basic I/O loop with a way to exit while using a package for <code>getIntegerFromUser</code> we made in class.</p>
  
  <p>Is there a way to assign values to Strings and then add them together when I call the method?</p>
  
  <p><strong>Update:</strong> I got some pseudo code from my professor to help me, and while I understand what he is trying to say, I am having some trouble with the <code>if</code>s. Will I be needing many, many <code>if</code> statements so that my converter will correctly handle the Roman numeral formatting or is there a manner in which I can do this with more efficiency? I've updated my code to reflect my placeholder method.</p>
  
  <p><strong>Update (Oct 28 2012):</strong> I got it working. Here's what I ended up using: </p>
  
  <pre><code>public static String IntegerToRomanNumeral(int input) {
      if (input &lt; 1 || input &gt; 3999)
          return "Invalid Roman Number Value";
      String s = "";
      while (input &gt;= 1000) {
          s += "M";
          input -= 1000;        }
      while (input &gt;= 900) {
          s += "CM";
          input -= 900;
      }
      while (input &gt;= 500) {
          s += "D";
          input -= 500;
      }
      while (input &gt;= 400) {
          s += "CD";
          input -= 400;
      }
      while (input &gt;= 100) {
          s += "C";
          input -= 100;
      }
      while (input &gt;= 90) {
          s += "XC";
          input -= 90;
      }
      while (input &gt;= 50) {
          s += "L";
          input -= 50;
      }
      while (input &gt;= 40) {
          s += "XL";
          input -= 40;
      }
      while (input &gt;= 10) {
          s += "X";
          input -= 10;
      }
      while (input &gt;= 9) {
          s += "IX";
          input -= 9;
      }
      while (input &gt;= 5) {
          s += "V";
          input -= 5;
      }
      while (input &gt;= 4) {
          s += "IV";
          input -= 4;
      }
      while (input &gt;= 1) {
          s += "I";
          input -= 1;
      }    
      return s;
  }
  </code></pre>