public class ArrTest { public static void main(String[] args) { int arr[]=new int[100],sum=0; for (int i = 0; i < arr.length; i++) { arr[i]=i+1; sum+=arr[i]; if((i+1)%20!=0)//打印! System.out.print(arr[i]+" "); else System.out.println(arr[i]); }//求和! System.out.println("元素和:"+sum); } }