zoukankan      html  css  js  c++  java
  • 笔头练习02

    //评委打分
    
    import java.util.Scanner;
    public class Test07 {
        public static void main(String[] args) {
            int[] arr = new int[6];
    
            Scanner sc = new Scanner(System.in);
    
    //        System.out.println("请输入第一个评委的打分: ");
    //        arr[0] = sc.nextInt();
    //
    //        System.out.println("请输入第二个评委的打分: ");
    //        arr[1] = sc.nextInt();
            for (int x = 0; x < arr.length; x++) {
                System.out.println("请输入第" + (x + 1) + "个评委的打分");
                arr[x] = sc.nextInt();
            }
            int max = getMax(arr);
            int min = getMin(arr);
            int sum = getSum(arr);
            int avg = (sum - max - min)/(arr.length - 2);
            System.out.println("该选手最后得分是: " + avg);
    
        }
    
        public static int getSum(int[] arr){
            int sum = 0;
            for(int x = 0; x<arr.length; x++) {
                sum += arr[x];
            }
            return sum;
        }
    
        public static int getMin(int[] arr){
            int min = arr[0];
            for(int x=1; x<arr.length; x++){
                if(arr[x] < min){
                    min = arr[x];
                }
            }
            return min;
        }
    
        public static int getMax(int[] arr){
            int max = arr[0];
    
            for(int x = 1; x<arr.length; x++){
                if(arr[x] > max){
                    max = arr[x];
                }
            }
            return max;
        }
    
        public static void printArray(int[] arr) {
            System.out.print("[");
            for (int x = 0; x < arr.length; x++) {
                if (x == arr.length - 1) {                      //数组中最后一位元素的写法
                    System.out.print(arr[x]);
                } else {
                    System.out.print(arr[x] + ",");
                }
            }
            System.out.println("]");
        }
    }
    
    
    //反转数组的元素
    public class Test06 {
        public static void main(String[] args) {
            int[] arr ={19,28,37,46,50};
    
            /*
            for(int start=0,end=arr.length-1;start<=end;start++,end--){
                int temp = arr[start];
                arr[start] = arr[end];
                arr[end] = temp;
            }*/
    
            reverse(arr);
            printArry(arr);
        }
    
        public static void reverse(int[] arr){
            for(int start=0,end=arr.length-1;start<=end;start++,end--){
                int temp = arr[start];
                arr[start] = arr[end];
                arr[end] = temp;
            }
        }
    
        public static void printArry(int[] arr){
            System.out.print("[");
            for(int x = 0;x < arr.length;x++){
                if(x == arr.length-1){                      //数组中最后一位元素的写法
                    System.out.print(arr[x]);
                }else{
                    System.out.print(arr[x] + ",");
                }
            }
            System.out.println("]");
        }
    }
    

      

  • 相关阅读:
    数组splice用法
    opacity 适配Ie
    直接贴页面,页面衔接处总会有一像素的间隔
    <script src='url'</script>显示问题
    弹出层
    CF789A. Anastasia and pebbles
    CF789C. Functions again
    HDU2161 Primes
    UVA11752 The Super Powers
    UVA11827 Maximum GCD
  • 原文地址:https://www.cnblogs.com/walkersss/p/14950389.html
Copyright © 2011-2022 走看看