How to improve the output for this factorial program? [closed]

Let’s say we have int n which is the factorial number

    int n=4;
    int result=1;
    for(int i=1;i<=n;i++)
    {
       result = result * i;
       System.out.print("1*");
       for(int j=1;j<i;j++)
       {
           System.out.print(j+"*");
       }
       System.out.println(i+"="+result);
    }

The result will be:

1*1=1
1*1*2=2
1*1*2*3=6
1*1*2*3*4=24

Leave a Comment