1. There are 10 judges to score, (remove one highest and one lowest) to get the average score. package ssa; import java.util.Scanner; public class lianxi { public static void main (String [] args) { int [] arry = new int [] {1,2,3,4,5,6,7,8 , 9,10}; for (int i = 0; i <arry.length-1; i ++) { for (int j = 0; j <arry.length-1-i; j ++) { if (arry [j] > arry [j + 1]) { int tmp = arry [j]; arry [j] = arry [j + 1]; arry [j + 1] = tmp; } } } int sum = 0; for (int i = 1; i <arry.length-1; i ++) { sum + = arry [i]; } System.out.println ("Average score:" + sum / (arry.length-2.0)); } }
2. Learn about Java random numbers by yourself, generate a random array of length 10 (each number ranges from 0 to 99), and output after sorting. package ssa; import java.util.Random; public class lianxi { public static void main (String [] args) { int [] arry = new int [10]; Random r = new Random (); for (int i = 0 ; i <arry.length; i ++) { arry [i] = r.nextInt (100); } int t; for (int i = 0; i <arry.length-1; i ++) { for (int j = 0 ; j <arry.length-1-i; j ++) { if (arry [j + 1]> arry [j]) { t = arry [j]; arry [j] = arry [j + 1]; arry [ j + 1] = t; } } } for (int i=0;i<arry.length;i++) { System.out.println(i); } } }
3. Make 7 out of 35 lottery programs. (It is 1 ~ 35 randomly generated 7 non-repeating numbers) package ssa; import java.util.Random; public class lianxi { public static void main (String [] args) { int a [] = new int [7]; Random r = new Random (); for (int i = 0; i <a.length; i ++) { a [i] = r.nextInt (35) +1; } for (int x = 0; x <a. length; x ++) { System.out.println (a [x]); } } }
4. Define an int array of length 10 (if there is no special instructions, static assignment and dynamic assignment can be), the maximum and minimum values in the array, and the number of odd and even numbers. package ssa; import java.util.Random; public class lianxi { public static void main (String [] args) { int a [] = {10, 20, 33, 34, 87, 90, 88, 9, 38, 44 }, q = 0; int o = 0, max = a [0], min = a [0]; for (int i = 0; i <a.length; i ++) { if (a [i]% 2 = = 0) { o = o + 1; } else { q = q + 1; } } for (int x = 0; x <a.length; x ++) { if (a [x]> max) { max = a [x]; } } for (int y = 0; y <a.length; y ++) { if (a [y] <min) { min = a [y]; } } System.out.println ("The maximum value is" + max + " , The minimum value is "+ min +", odd number has "+ q +", even number has "+ o +" number "); }