//自己一个计算1-20阶乘的程序,要求遍历个数阶乘及总和,为什么算出的和和别人的不一样呢?
public class Jiecheng{
public static void main(String[] args){ long[] a = new long[20]; 
for(int j=0;j<20;j++){
a[j] = j+1;
//System.out.print(a[j]);
}

  for(int i=1;i<a.length;i++){

a[i] = a[i-1]*(i+1);

}
long sum = 0; 
for(int i=0;i<a.length;i++){
sum = sum + a[i];

System.out.println(sum);
}
}
//用for循环了3个输入,但是他们是什么名字?是s.i?public class Test2{
public static void main(String[] args)throws Exception{
for(int i=0;i<3;i++){
byte[] b = new byte[13];
System.in.read(b);
String s = new String(b);
}
}}

解决方案 »

  1.   

    第二个 用b[i] = Integer.valueof(s);
      

  2.   


    public class Test
    {
        public static void main( String[] args )
        {
            Test test = new Test();
            test.factorial( 20 );
        }
        public void factorial(int param){
            long count = 0 ;
            long sum = 0;
            for( int i = 1 ; i <= param ; i++){
                if(i == 1){
                    count = i;
                }else{
                    count = count * i;
                }
                sum += count;
                System.out.println(i + "的阶乘值为:" +count);
            }
            System.out.println("总和为:" + sum);
        }
    }1的阶乘值为:1
    2的阶乘值为:2
    3的阶乘值为:6
    4的阶乘值为:24
    5的阶乘值为:120
    6的阶乘值为:720
    7的阶乘值为:5040
    8的阶乘值为:40320
    9的阶乘值为:362880
    10的阶乘值为:3628800
    11的阶乘值为:39916800
    12的阶乘值为:479001600
    13的阶乘值为:6227020800
    14的阶乘值为:87178291200
    15的阶乘值为:1307674368000
    16的阶乘值为:20922789888000
    17的阶乘值为:355687428096000
    18的阶乘值为:6402373705728000
    19的阶乘值为:121645100408832000
    20的阶乘值为:2432902008176640000
    总和为:2561327494111820313
    第二题不明白要问的是什么能具体点吗?
      

  3.   

    楼主第二个问题 是是不是  要问字节数组的内容是什么啊?
    for(int i=0;i<3;i++){
    byte[] b = new byte[13];
    System.in.read(b);
    //String s = new String(b);
    for(int i=0;i<b.length;i++){
    System.out.print(b[i]+" ")
    }
    }
      

  4.   

    //用for循环了3个输入,但是他们是什么名字?是s.i?public class Test2{
    public static void main(String[] args)throws Exception{
    for(int i=0;i<3;i++){
    byte[] b = new byte[13];
    System.in.read(b);
    String s = new String(b);
    }
    }应该是想问输入的13个字节怎么得到?b[i]