printArray(arr);
printArray(st);
q:while(true){
int temp = sc.nextInt();
switch (temp) {
case 1:
reversalArray(arr);
printArray(arr);
break;
case 2:
System.out.println("请输入要查找的值:");
int key = sc.nextInt();
int mark = search(arr,key);
System.out.println(mark);
break;
case 3:
int max = getMax(arr);
System.out.println(max);
break;
case 4:
sortArray(arr);
printArray(arr);
break;
case 886:
break q;
default:
System.out.println("对不起,没有这项功能");
break;
}
}
}
public static void printArray(int[] arr) { //打印数组,数组的遍历
System.out.print("您输入的数组:{");
for (int x = 0;x < arr.length ;x ++ ) {
System.out.print(arr[x] + " ");
}
System.out.println("}");
}
public static void printArray(String[] arr) { //打印数组,数组的遍历,方法重载
for (int x = 0;x < arr.length ;x ++ ) {
System.out.println(arr[x]);
}
}
public static void reversalArray(int[] arr) { //反转数组
for (int x = 0;x < arr.length /2 ;x ++ ) {
int temp = arr[x];
arr[x] = arr[arr.length - x - 1];
arr[arr.length - x - 1] = temp;
}
}
public static int getMax(int[] arr) { //获取数组最大值
int max = arr[0];
for (int x = 1;x < arr.length ;x ++ ) {
if (max < arr[x]) {
max = arr[x];
}
}
return max;
}
public static int search(int[] arr,int key) { //查找
for (int x = 0;x < arr.length ;x ++ ) {
if (key == arr[x]) {
return x;
}
}
return -1;
}
public static void sortArray(int[] arr) { //排序
for (int x = 0;x < arr.length - 1 ;x ++ ) {
for (int y = 0;y < arr.length - x - 1 ;y ++ ) {
if (arr[x] > arr[x + 1]) {
int temp = arr[x];
arr[x] = arr[x + 1];
arr[x + 1] = temp;
}
}
}
}
}