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

第六周练习

时间:2020-04-17 12:36:49      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:order   计数   ack   stat   pad   keyword   数组   aci   highlight   

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

第六周练习

标签:order   计数   ack   stat   pad   keyword   数组   aci   highlight   

原文地址:https://www.cnblogs.com/dh200031/p/12719016.html

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