java数组---数组的使用(打印,求和,最大值)
public static void main(String[] args) {
int[] arrays={1,2,3,4,5}; //打印该数组
for (int i = 0; i < arrays.length; i++) {
System.out.println(arrays[i]);
}
System.out.println("========================");
int sum=0; //求他们的和
for (int i = 0; i < arrays.length; i++) {
sum=sum+arrays[i];
}System.out.println(sum);
System.out.println("========================");
int max=arrays[0]; //求最大值
for (int i = 0; i < arrays.length; i++) {
if (arrays[i]>max){
max=arrays[i];
}
}
System.out.println(max);
}