public class Test {
public static void main(String[] args) {
System.out.println(arrayMax(new int[]{1, 2, 3, 4, 5}));
System.out.println(arrayMin(new int[]{11,1,5,7}));
System.out.println(arraySum(new int[]{3,7,11}));
System.out.println(arrayJoin(new int[]{1,2,3},new int[]{3,6,7}));
System.out.println(arraySub(new int[]{3, 6, 7, 11, 13, 16}, 0, 2));
int[] date=new int[]{3,6,7,11};
arrayPrint(date);
printReversal(date);
}
//1.计算数组中最大值
public static int arrayMax(int[] date) {
int max = date[0];
for (int i = 0; i < date.length; i++) {
if (date[i] > max) {
max = date[i];
}
}
return max;
}
//2.计算数组中最小值
public static int arrayMin(int[] date) {
int min = date[0];
for (int i = 0; i < date.length; i++) {
if (date[i] < min) {
min = date[i];
}
}
return min;
}
//3.计算数组值之和
public static int arraySum(int[] date) {
int total = 0;
for (int i = 0; i < date.length; i++) {
total += date[i];
}
return total;
}
//4.数组拼接
public static int[] arrayJoin(int[] a, int[] b) {
int length = a.length + b.length;
int[] date = new int[length];
for (int i = 0; i < a.length; i++) {
date[i] = a[i];
}
int flag = a.length;
for (int i = 0; i < b.length; i++) {
date[flag] = b[i];
flag++;
}
return date;
}
//5.数组截取
public static int[] arraySub(int[] date, int start, int end) {
int length = end - start;
int[] result = new int[length];
int flag = start;
for (int i = 0; i < length; i++) {
result[i] = date[length];
flag++;
}
return result;
}
//[start, end)
//6.数组打印
public static void arrayPrint(int[] date) {
for (int temp:date) {
System.out.print(temp+"、");
}
}
//7.数组反转
public static void printReversal(int[] date){
for(int i = date.length-1; i>=0; i--){
System.out.print(date[i]+"、");
}
}
}