第六周练习

Posted dh200031

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第六周练习相关的知识,希望对你有一定的参考价值。

1.有10个评委打分,(去掉一个最高一个最低)求平均分<br>package yugh;
import java.util.*;
public class ku {
        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);
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2.自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出。<br>package yugh;
import java.util.Random;
public class ll {
         public static void main(String[] args) {
         Random s=new Random();
         int i=s.nextInt(100);
         Random r=new Random();
         for(int =0;j<10;j++) {
             int j = r.nextInt(100);
             System.out.println(j);
          
     }
         }
     }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
3.制作彩票35选7程序。 (就是1~35随机生成7个不重复的数)<br>package yugh;
import java.util.Random;
public class oi {
         public static void main(String[] args) {
              Random rand = new Random();
              int []arr=new int[7];
              for(int i=0;i<7;i++) {
                 arr[i]=rand.nextInt(35)+1;
                 
            }
             for (int i = 0; i < arr.length; i++) {
                System.out.println(arr[i]);
                 
             }
          
       
     
       }
     }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
4.定义一个长度为10的int数组(如果没有特殊说明,静态赋值动态赋值都可以),统计数组中的最大值、最小值、以及奇 数和偶数的个数<br>package yugh;
import java.util.Random;
public class oy {
        public static void main(String[] args){
             int[] score=new int[10];
                Random r=new Random();
                for(int i=0;i<score.length;i++){
                    score[i]=r.nextInt(100);
                }
                System.out.println("原数组为:");
                for(int i=0;i<score.length;i++){
                    System.out.println(score[i]);
                }
                for(int i=0;i<score.length-1;i++){
                    for(int j=0;j<score.length-1-i;j++){
                        if (score[j]>score[j+1]){
                            int tmp=score[j];
                            score[j]=score[j+1];
                            score[j+1]=tmp;
                        }
                    }
                }
                int a=0,b=0;
                for (int i=0;i<score.length;i++){
                    if (score[i]%2==0){
                        b++;
                    }
                    else{
                        a++;
                    }
                }
                System.out.println("最小值为:"+score[0]);
                System.out.println("最大值为:"+score[score.length-1]);
                System.out.println("奇数个数:"+a);
                System.out.println("偶数个数:"+b);
            }
        }

以上是关于第六周练习的主要内容,如果未能解决你的问题,请参考以下文章

第六周练习

第六周上机练习

第六周上机练习

第六周上机练习

第六周上机练习

JAVA第六周上机练习