第七次作业

有10个评委打分,(去掉一个最高一个最低)求平均分。

package finish;

import java.util.Scanner;

public class ttt {

    public static void main(String[] args) {
        int a[] = new int[10];
        int sum = 0, max = 0, min = 1000;
        System.out.println("请输入分数");
        for (int i = 0; i < a.length; i++) {
            Scanner input = new Scanner(System.in);
            a[i] = input.nextInt();
        }
        for (int j = 0; j < a.length; j++) {
            if (a[j] > max) {
                max = a[j];
            }
        }
        for (int x = 0; x < a.length; x++) {
            if (a[x] < min) {
                min = a[x];
            }
        }
        for (int y = 0; y < a.length; y++) {
            sum += a[y];
        }
        System.out.println("平均分是" + (sum -max-min)/ 8.0);
    }

}

自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出。{45,88,72,32,}

package finish;


import java.util.Random;
import java.util.Scanner;

public class ttt {

    public static void main(String[] args) {
        int a[] = new int[10];
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            a[i] = r.nextInt(100);
        }
        for (int i = 0; i < a.length - 1; i++) {
            for (int n = 0; n < a.length - 1 - i; n++) {
                if (a[n] > a[n + 1]) {
                    int c = a[n];
                    a[n] = a[n + 1];
                    a[n + 1] = c;
                }
            }

        }
        for (int x = 0; x < a.length; x++) {
            System.out.println(a[x]);
        }

    }
}

制作彩票35选7程序。 (就是1~35随机生成7个不重复的数)

package finish;


import java.util.Random;

public class ttt {

    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]);
        }

    }

}

定义一个长度为10的int数组(如果没有特殊说明,静态赋值动态赋值都可以),统计数组中的最大值、最小值、以及奇 数和偶数的个数

package finish;


import java.util.Random;

public class ttt {

    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("最大值是" + max + ",最小值是" + min + ",奇数有" + q + "个,偶数有" + o + "个");
    }
}

 

posted @ 2020-04-16 12:17  Day丶T  阅读(155)  评论(0编辑  收藏  举报