import java.util.Scanner;
public class day_4_5 {
public static void main(String[] args) {
/*数组的常见操作*/
//遍历
int[] arr = {3, 5, 2, 1, 4};
int max = arr[0];
int max1 = 0;
int max2 = 0;
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
//取数组中的最大值
for (int i = 1; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}
}
;
System.out.println(max);
for (int i = 1; i < arr.length; i++) {
if (arr[max1] < arr[i]) {
max1 = i;
}
}
;
System.out.println(arr[max1]);
//取数组中的最小值
for (int i = 1; i < arr.length; i++) {
if (arr[max2] > arr[i]) {
max2 = i;
}
}
;
System.out.println(arr[max2]);
//查询输入的数据是否在数组中存在
// Scanner sc = new Scanner(System.in);
// System.out.println("请输入一个数字:");
// int num = sc.nextInt();
// int[] arr4 = {1, 2, 3, 4, 5};
// for (int i = 0; i < arr4.length; i++) {
// if (num == arr4[i]) {
// System.out.println("数据存在");
// break;
// }
// }
int[] arr5 = {1, 2, 3, 4, 5};
//反转前
for(int i = 0; i < arr5.length;i++){
System.out.print(arr5[i] + " ");
}
//数组反转
for (int i = 0, j = arr5.length - 1; i < arr5.length / 2; i++, j--) {
int temp = arr5[i];
arr5[i] = arr5[j];
arr5[j] = temp;
}
//反转后
for(int i = 0; i < arr5.length;i++){
System.out.print(arr5[i] + " ");
}
}
}
标签:arr,length,int,反转,System,arr5,数组,操作,out
From: https://www.cnblogs.com/wyj497022944/p/18073262