title: Printing from a loop
body: <p>I need to print the factors of a perfect number. Here's the gist of my main class:</p>
  
  <pre><code>ArrayList&lt;Integer&gt; perfNums = new ArrayList&lt;&gt;();
  Scanner in = new Scanner(System.in);
  System.out.print("Enter the upperbound: ");
  upperbound = in.nextInt();
  for (int i = 1; i &lt;= upperbound; i++) {
       if (isPerfect(i)) { //boolean to check if number is a perfect number
          perfNums.add(i);
       }
  }
  
  System.out.println("Perfect numbers between 1 and " + upperbound + " are:");
  for (int i = 0; i &lt; perfNums.size(); i++) {
       System.out.print(perfNums.get(i) + " = ");
       printFactor((int)perfNums.get(i));
       System.out.println();
  }
  </code></pre>
  
  <p>Here's the <em>printFactor</em> class.</p>
  
  <pre><code>private static void printFactor(int number){
      int factor = 1;
      while(factor &lt; number){
          if (number%factor == 0) System.out.print(factor+ " + ");
          //I don't know how to print the + sign otherwise.
          factor++;
      }
  }
  </code></pre>
  
  <p>And here's a sample output: </p>
  
  <pre><code>Enter the upperbound: 10000
  Perfect numbers between 1 and 10000 are:
  6 = 1 + 2 + 3 + 
  28 = 1 + 2 + 4 + 7 + 14 + 
  496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 + 
  8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064 + 
  </code></pre>
  
  <p>I've got the main gist of it but I've struggled with an output issue. Due to the restrictions of my online submission system, my output needs to fit exact specifications. </p>
  
  <p><strong>My question is how do I go about printing all the factors of my perfect number but removing the + sign at the end?</strong> (e.g)<code>6 = 1 + 2 + 3</code></p>
  
  <p>I'm not too sure of many methods to print from a while loop. Would a for-loop be better for my goals? Or are there alternative methods to print the factors of a number?</p>