title: JAVA: How to combine message boxes with multiple outputs
body: <p>I am learning Java and have a rather simple program that returns a series of numbers in accordance with the <a href="http://en.wikipedia.org/wiki/Collatz_conjecture" rel="nofollow">Collatz Conjecture</a>. I can have it output into the console or have many <code>JOptionPane.showMessageDialog()</code> windows pop up, one with each number in it.  </p>
  
  <p>How would I combine the <code>JOptionPane.showMessageDialog()</code>'s to show all the outputs in one <code>JOptionPane.showMessageDialog()</code>?</p>
  
  <p>Code:  </p>
  
  <pre><code>package collatz;
  
  import java.util.Random;
  import javax.swing.*;
  
  public class Collatz {
  
  /**
   * Demonstrates the Collatz Cojecture
   * with a randomly generated number
   */
  
  public static void main(String[] args) {
      Random randomGenerator = new Random();
      int n = randomGenerator.nextInt(1000);
  
      JOptionPane.showMessageDialog(null, "The randomly generated number was: " + n);
  
  
      while(n &gt; 1){
          if(n % 2 == 0){
              n = n / 2;
              JOptionPane.showMessageDialog(null, n);
          }
          else{
              n = 3 * n + 1;
              JOptionPane.showMessageDialog(null, n);
          }
      }
  
      JOptionPane.showMessageDialog(null, n);
      JOptionPane.showMessageDialog(null, "Done.");
  
  }
  
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>--
  ZuluDeltaNiner</p>