title: Factorial program using for loops
body: <p>I am an AP Computer Science student and I was wondering how to finish up my factorial code using for loops. Here is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  public class Factorial 
  {
  
      public static void main(String[] args) 
      {
          int num;
          int factorial = 1;
          int i;
          Scanner input = new Scanner(System.in);
          System.out.println("Enter a number: ");
          num = input.nextInt();
          for(i = 1; i &lt;= num; i++)
          {
              factorial *= i;
          }
          System.out.println("!"+num+"="+factorial);
  </code></pre>
  
  <p>I tested it using eclipse and it worked for all integers until (and including) 12. When I entered 13, it gave me an incorrect number. Can someone explain to me why that is and how to rectify it?</p>
  
  <p>Also, the assignment says I need to print out the numbers that I'm multiplying in addition to the answer <strong>(i.e. if num = 5, then the output is 5! = 5*4*3*2*1 = 120)</strong>. Can someone point me in the right direction for that issue?</p>