1. Hay 10 jueces para anotar (elimine uno más alto y uno más bajo) para obtener el puntaje promedio.
paquete de trabajo de calsswork; import java.util.Scanner; public class text1 { public static void main (String [] args) { Scanner sc = new Scanner (System. in ); int a [] = nuevo int [ 10 ]; suma doble = 0 ; int b = 1 ; doble c = 0 ; for ( int i = 0 ; i <a.length; i ++ ) { Sistema.out .println ( " 输入 数组" ); a [i] = sc.nextInt (); } for ( int x = 0 ; x <a.length - 1 ; x ++ ) { for ( int y = 0 ; y <a.length - 1 - x; y ++ ) { if (a [y]> a [y + 1 ]) { int temp = a [y + 1 ]; a [y + 1 ] = a [y]; sí]= temp; } } } para ( int n: a) { Sistema. out .println (n + " 、" ); } para (; b <a.length - 1 ; b ++ ) { sum + = a [b]; c = suma / b; } Sistema. out .println ( " 平均数 :" + c); } }
2. Aprenda sobre los números aleatorios de Java usted mismo, genere una matriz aleatoria de longitud 10 (cada número oscila entre 0 y 99) y envíe la salida después de la clasificación.
paquete de trabajo de calsswork; import java.util.Scanner; public class text1 { public static void main (String [] args) { int arr [] = new int [ 10 ]; Aleatorio r = nuevo Aleatorio (); for ( int i = 0 ; i <arr.length; i ++ ) { arr [i] = r.nextInt ( 100 ); Sistema. out .print (arr [i] + " , " ); } Sistema.fuera .println (); Sistema. out .println ( " 随机 数 开始 排序 !!!" ); for ( int x = 0 ; x <arr.length - 1 ; x ++ ) { for ( int y = 0 ; y <arr.length - 1 - x; y ++ ) { if (arr [y]> arr [y + 1 ]) { int temp = arr [y + 1 ]; arr [y + 1 ] = arr [y]; arr [y]= temp; } } } para ( int n: arr) { Sistema. out .println (n + " , " ); } } }
3. Realice 7 de los 35 programas de lotería. (Es decir, 1 ~ 35 genera aleatoriamente 7 números no repetidos)
paquete de trabajo de calsswork; import java.util.Random; public class text1 { public static void main (String [] args) { int [] a = new int [ 35 ]; Aleatorio r = nuevo Aleatorio (); para ( int i = 0 ; i <a.length; i ++ ) { a [i] = r.nextInt ( 34 ) + 1 ; } int [] b = nuevo int [ 7]; para ( int j = 0 ; j < 7 ; j ++ ) { b [j] = a [r.nextInt ( 36 )]; } para ( int i: b) { Sistema. out .print (i + " " ); } } }
4. Defina una matriz int con una longitud de 10, y cuente los números máximos, mínimos, impares y pares en la matriz
paquete de trabajo de calsswork; import java.util.Scanner; public class text1 { public static void main (String [] args) { Scanner sc = new Scanner (System. in ); int arr [] = nuevo int [ 10 ]; int js = 0 , os = 0 ; for ( int i = 0 ; i <arr.length; i ++ ) { Sistema. out .println ( " 请 输入 第" + (i +1 ) + " 个数 :" ); arr [i] = sc.nextInt (); } int max = arr [ 0 ], min = arr [ 0 ]; para ( int x = 1 ; x <longitud de arr; x ++ ) { if (arr [x]> max) { max = arr [x]; } else if (arr [x] < min) { min = arr [x]; } } para ( inty = 0 ; y <longitud de arr; y ++ ) { if (arr [y]% 2 == 0 ) { os ++ ; } else { js ++ ; } } System. out .println ( "El valor máximo es: " + max + " , " + " El valor mínimo es: " + min); System. out .println ( " El número impar es: " + js + ", " + " El número par es: " + os); } }