public static void main(String[] args) {
int [] arrys= {1,2,3,4,5};
for (int i = 0; i < arrys.length; i++) {
System.out.println(arrys[i]);
}
int sum=0;
for (int i = 0; i < arrys.length; i++) {
sum+=arrys[i];
}
System.out.println("总和为"+sum);
int max=arrys[0];
for (int i = 1; i < arrys.length; i++) {
if(arrys[i]>max)
max=arrys[i];
}
System.out.println("最大值为 "+max);
}
public static void main(String[] args) {
int [] arrays= {1,2,3,4,5};
int [] reverse=reverse(arrays);
printArray(reverse);
}
public static void printArray(int[]arrays) {
for (int i = 0; i < arrays.length; i++) {
System.out.println(arrays[i]+" ");
}
}
public static int [] reverse(int[] arrays) {
int [] result=new int [arrays.length];
for(int i=0,j=arrays.length-1;i<arrays.length;i++,j--) {
result[i]=arrays[j];
}
return result;
}
转载请注明原文地址:https://blackberry.8miu.com/read-715.html