int  n ;//用来接收输入的数字。
StringBuffer sb = new StringBuffer();
int sum = 1;
for (int i = 1; i <= n; i++) {
if (i < n) {
sb.append(i + "*");
}
if (i == n) {
sb.append(i);
}
sum *= i;
}
System.out.println(n + "! = " + sb.toString() + "=" + sum);

解决方案 »

  1.   

    单用一个for循环不是就出来了么?
      

  2.   


    package test;
    import junit.framework.TestCase;public class CommonTest extends TestCase{

    public void testResource(){
    System.out.println(test(4));
    }

    public static int test(int n){
    int result = 1;
    for(int i = 1; i<=n;i++){
    result *= i;
    }
    return result;
    }
    }
      

  3.   


    int n = 10;
    long result = 1l;
    System.out.print(n + "!=");
    for(int i=1; i<n; i++) {
    result *= i;
    System.out.print(i + "*");
    }
    result *= n;
    System.out.println(n + "=" + result);这样只有循环了貌似就