public static void main(String[] args) { // TODO 自动生成的方法存根 int []a={1,2,3,4,5}; int sum=0; int max = 0; for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); }//遍历数组 System.out.println(""); System.out.println("----------"); for (int b:a) { System.out.print(b+" "); }//遍历数组,这种方法不能单独提取某个下标的值 System.out.println(""); System.out.println("----------"); for (int i = 0; i <=a.length; i++) { sum+=i; }System.out.print("sum="+sum); //求数组和 System.out.println(""); System.out.println("----------"); for (int i = 0; i < a.length; i++) { if(a[i]>max) { max=a[i]; } }System.out.print("max="+max); //求数组最大值 }
吾独矣
终极愿望世界和平