数组的使用
public class ArrayDemo03 {
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+=arrays[i];
}
System.out.println(sum);
System.out.println("================");
int max_num=arrays[0];
for (int i=1;i<arrays.length;i++){
if (max_num<arrays[i]){
max_num=arrays[i];
}
}
System.out.println(max_num);
}
}
public class ArrayDemo04 {
public static void main(String[] args) {
int[] arrays={1,2,3,4,5};
for (int array:arrays){
System.out.println(array);
}
printArrays(arrays);
printArrays(reverse(arrays));
}
public static void printArrays(int[] arrays){
for (int i=0; i<arrays.length;i++){
System.out.print(arrays[i]+" ");
}
}
public static int[] reverse(int[] arrays){
int[] result = new int[arrays.length];
for (int i=0;i<arrays.length;i++){
result[i]=arrays[arrays.length-i-1];
}
return result;
}
}