package hm_4_16; /* * 第一题升序排列 */ import java.util.Arrays; public class test01 { public static void main(String[] args) { int[] arr = {26,36,96,25,6}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length-1-i; j++) { if (arr[j]>arr[j+1]) { int a = arr[j]; arr[j]=arr[j+1]; arr[j+1]=a; } } } System.out.println(Arrays.toString(arr)); } } package hm_4_16; import java.util.Scanner; /* * 定义数组数输入值查看时否在数组里 */ public class test02 { public static void main(String[] args) { int[] arr = {26,36,96,25,6,88}; Scanner sca= new Scanner(System.in); System.out.println("输入一个数:"); int a = sca.nextInt(); for (int i = 0; i < arr.length; i++) { if (arr[i]==a) { System.out.println("下标为:"+i); return; } } System.out.println("Not Found"); } } package hm_4_16; /* * 矩阵 */ public class test03 { public static void main(String[] args) { int arr[][] = {{1,5,9,6},{96,32,45,61},{11,24,36,45}}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { System.out.print(arr[i][j]+" "); } System.out.println(); // System.out.println("---"); } } } package hm_4_16; /* * 求二维数组最大值 */ public class test04 { public static void main(String[] args) { int arr[][] = {{1,5,9,6},{96,32,45,61},{11,24,36,45}}; int max =arr[0][0]; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { if (max<arr[i][j]) { int a= max; max=arr[i][j]; arr[i][j]=a; // System.out.println(arr[i][j]); } } } System.out.println(max); } }