4.16 Computer operation

1. There are 10 judges to score, (remove one highest and one lowest) to get the average score.

package zy;
import java.util.Scanner;//
public class hj {

    public static void main(String[] args) {
         Scanner input=new Scanner(System.in);//
         int[] array = {100,50,90,90,90,90,90,90,90,90};
         int index = 0, sum = 0, temp = 0, avg = 0 ;
         for (int i = 0; i < array.length - 1; i++) {
         for (int j = i + 1; j < array.length; j++) {
         if (array[j] < array[i]) { 
         temp = array[i];
         array[i] = array[j];
         array[j] = temp;
         }
     }
 }
         while (array.length != index) {
         sum += array[index];
         index++;
         }
         do {
         sum = sum - array[0] - array[array.length-1]; 
         } while (false);
         avg = sum / 8;
         System.out.println(avg);
    }
    }

2. Generate a random array of length 10 (each number ranges from 0 to 99), output after sorting.

package zy;
 import java.util.Scanner;
 import java.util.Arrays;
 import java.util.Random;
 import java.util.Scanner; 

public  class hj { 

    public  static  void main (String [] args) { 

         Scanner input = new Scanner (System.in); 
         System.out.println ( "Please enter the range of random numbers" ); 
            System.out.println ( "Please enter the maximum value in the range" );
             int   t = input.nextInt (); 
            System.out .println ( "Please enter the minimum value in the range" );
             int t1 =input.nextInt();
            int a[]=new int [4];
            Random r=new Random();
            for(int y=0;y<a.length;y++) {
                a[y]=t1+r.nextInt(t);
                
            }
            Arrays.sort(a);
            for(int  u:a) {
                System.out.print(u+"\t");
            }
        }
    }

3. Make 7 out of 35 lottery programs. (That is, 1 ~ 35 randomly generates 7 non-repeating numbers)

package zy;
import java.util.Random;
public class hj {

    public static void main(String[] args) {
          int[] score = new int[7];
            Random r = new Random();
            for (int i = 0; i < score.length; i++)
            {
                score[i] = r.nextInt(35) + 1;
            }
            System.out.println("35选7号码为:");
            for (int i = 0; i < score.length; i++)
            {
                System.out.println(score[i]);
            }
        }
    }

 

4. Define an int array with a length of 10 (if there is no special instructions, static assignment and dynamic assignment can be used), the maximum and minimum values ​​in the array, and the number of odd and even numbers

package zy;
public class hj {

    public static void main(String[] args) {


        int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        int max = arr[0];
        int min = arr[1];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            } else if (min > arr[i]) {
                min = arr[i];
            }
        } 
        System.out.println ( "The maximum value of the array is" + max + "The minimum value of the array is" + min); 

        int count1 = 0 ;
         int count2 = 0 ;
         for ( int j = 0; j <arr.length ; j ++ ) {
             if (j% 2! = 0 ) { 
                count1 ++ ; 
            } else { 
                count2 ++ ; 
            } 
        } 
        System.out.println ( "odd number has" + count1 + "number," + "even number has" + count2 + "个" ); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/s-j926blog/p/12711722.html