public class Array1 {
public static void main(String[] args) {
int [] num={1,2,3,4,5};
System.out.println("原数组为");
for(int i=0;i<num.length;i++){
if(i==num.length-1){
System.out.println(num[i]);
}
else {
System.out.print(num[i]);
}
}
System.out.println("---------------");
//比较最值
int max=-1,min=9999;
for(int i=0;i<num.length;i++){
if(num[i]>max){
max=num[i];
}
if(num[i]<min){
min=num[i];
}
}
System.out.println("最大值为:"+max+" 最小值为:"+min);
//求和
int sum=0;
for(int i=0;i<num.length;i++){
sum+=num[i];
}
System.out.println("数组元素之和为"+sum);
//反转数组
int []reserve=new int[5];
int x=num.length-1;
for(int j=0;j<num.length;j++){
reserve[j]=num[x];
x--;
}
System.out.println("反转后的数组为");
print(reserve);
System.out.println("\n");
//二维数组
System.out.println("二维数组为");
int[][] doub={{1,2},{2,3},{3,4},{4,5}};
for(int i=0;i<doub.length;i++){
for(int j=0;j<doub[0].length;j++){
System.out.print(doub[i][j]);
}
}
}
//定义方法
public static void print(int[] a){
for(int i=0;i<a.length;i++){
System.out.print(a[i]);}
}
}