public class JCH { public static void main(String[] args) { //数组 int[] a = new int[3]; a[0] = 1; a[1] = 2; a[2] = 3; //a[3] = 4;最大就是长度减一,超出运行报错(从0开始) int len = a.length;//获取数组成都 System.out.println("数组的长度 =" + len); for(int i=0;i< a.length;i++) System.out.println("a["+i+"]=" + a[i]); System.out.println("a[0]=" + a[0]); int b[]; // 用循环实现阶乘 int n = 12; //4!=1*2*3*4=24 long l = 1;//阶乘计算结果 for(int i = 1;i <= n; i ++){ l =l * i ; System.out.println("l =" + l); } System.out.println(n + "!=" + l ); //1+1/2!+1/3!+.....+1/20!=? int y = 20; double d = 0; for(int k = 1;k <= y;k++) { long s = 1; for(int i = 1;i <= k; i ++){ //计算阶乘 k! s =s * i ; System.out.println(s + "!=" + s); } d = d + 1/(double)s; } System.out.println("1/"+ y +"!=" + d); //循环嵌套 花三角形 int m = 10; //行数 for(int i = 1;i <= m;i++){ for(int j = 1;j <= i;j++){ System.out.print("*"); } System.out.println(); } for(int i = m;i >= 1;i--) { for(int j = 1;j <= i;j++) { System.out.print("*"); } System.out.println(); } /* for(int i = m - 1;i >= 1;i--){ for(int j = 1;j <= i;j++){ System.out.print("*"); } System.out.println(); }*/ } }