码迷,mamicode.com
首页 > 其他好文 > 详细

第七周上级练习

时间:2020-04-16 15:28:29      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:static   col   string   span   rand   package   ann   can   rgs   

package task1;
import java.util.*;
public class q {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] a = new int[10];
        System.out.println("请输入10位评委的分数:");
        for (int i = 0; i < 10; i++) {
            a[i] = input.nextInt();
        }
        int max, min, sum;
        max = a[0];
        min = a[0];
        sum = 0;
        for (int i = 0; i < 10; i++) {
            if (max < a[i]) {
                max = a[i];
            }
            if (min > a[i]) {
                min = a[i];
            }
            sum = sum + a[i];
        }
        int aver;
        aver = (sum - max - min) / 8;
        System.out.println("去掉最高分和最低分后的平均分是:" + aver);
    }
}
package task1;
import java.util.*;
public class q {
    public static void main(String[] args) {
        int[] a = new int[10];
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            a[i] = r.nextInt(100);
        }
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        System.out.println("排序后输出为:");
        for (int i = 0; i < 10; i++) {
            System.out.println( a[i]);
        }
    }
}
package task1;
import java.util.*;
public class q {
    public static void main(String[] args) {
        int[] a = new int[7];
        Random r = new Random();
        for (int i = 0; i < 7; i++) {
            a[i] = r.nextInt(35) + 1;
        }
        System.out.println("随机生成的数为:");
        for (int i = 0; i < 7; i++) {
            System.out.println(a[i]);
        }
    }
}

 

  

第七周上级练习

标签:static   col   string   span   rand   package   ann   can   rgs   

原文地址:https://www.cnblogs.com/sehnsucht/p/12712768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!