from loop to Nested loops ?

Posted by WM on Stack Overflow See other posts from Stack Overflow or by WM
Published on 2010-05-10T17:45:19Z Indexed on 2010/05/10 17:54 UTC
Read the original article Hit count: 217

Filed under:
|

I have this program that returns a factorial of N. For example, when entering 4,,, it will give 1! , 2! , 3!

How could I convert this to use nested loops?

public class OneForLoop
{   
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);     
        System.out.print("Enter a number : ");
        int N = input.nextInt();                
        int factorial = 1;   

        for(int i = 1; i < N; i++)
        {
             factorial *= i;         
             System.out.println(i + "! = " + factorial); 
        }         
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about homework