title: Trying to display factors of integers, but having difficulties
body: <p>I'm new to programming, I'm not sure where I'm going wrong with this one.</p>
  
  <p>Here is my main method:</p>
  
  <pre><code>import java.util.*;
  public class DisplayFactors
  {
      public static void main(String[] args)
      {
          Scanner scan = new Scanner(System.in);
          System.out.print("Enter a integer: ");
          String input1 = scan.nextLine();
          int input = Integer.parseInt(input1);
  
          FactorGenerator factor = new FactorGenerator(input);
  
          System.out.print(factor.getNextFactor());
  
          while (!factor.hasMoreFactors())
          {
              System.out.print(factor.getNextFactor());
          }
      }   
  }
  </code></pre>
  
  <p>Here is my class:</p>
  
  <pre><code>public class FactorGenerator {
  
      private int num;
      private int nextFactor;
  
      public FactorGenerator(int n)
      {
          num = nextFactor = n;
      }
  
      public int getNextFactor()
      {
          int i = nextFactor - 1 ;
  
          while ((num % i) != 0)
          {
              i--;
          }
          nextFactor = i;
          return i;
      }
  
      public boolean hasMoreFactors()
      {
          if (nextFactor == 1)
          {
              return false;
          }
          else
          {
              return true;
          }
      }
  }
  </code></pre>
  
  <p>Currently if I enter 15 as the integer I only get one factor back, which is 5, but I need it to display all the factors: 15, 5, 3 and 1. Where am I going wrong?</p>