Nested for Loop : For Loop « Statement Control « Java Tutorial






public class MainClass {
  public static void main(String[] args) {
    long limit = 20L;
    long factorial = 1L;

    for (long i = 1L; i <= limit; i++) {
      factorial = 1L;

      for (long factor = 2; factor <= i; factor++) {
        factorial *= factor;
      }
      System.out.println(i + "! is " + factorial);
    }
  }
}
1! is 1
2! is 2
3! is 6
4! is 24
5! is 120
6! is 720
7! is 5040
8! is 40320
9! is 362880
10! is 3628800
11! is 39916800
12! is 479001600
13! is 6227020800
14! is 87178291200
15! is 1307674368000
16! is 20922789888000
17! is 355687428096000
18! is 6402373705728000
19! is 121645100408832000
20! is 2432902008176640000








4.6.For Loop
4.6.1.The for Statement
4.6.2.For statement in detail
4.6.3.A loop allows you to execute a statement or block of statements repeatedly
4.6.4.The numerical for loop
4.6.5.Infinite For loop Example
4.6.6.initialization_expression: define two variables in for loop
4.6.7.Declare multiple variables in for loop
4.6.8.Multiple expressions in for loops
4.6.9.To omit any or all of the elements in 'for' loop: but you must include the semicolons
4.6.10.Keeping the middle element only in for loop
4.6.11.Using the Floating-Point Values as the control value in a for loop
4.6.12.Nested for Loop
4.6.13.Java's 'labeled for' loop
4.6.14.Print out a Diamond