JAVA第七周上机练习

2021-02-15 20:19

阅读:554

标签:col   pac   alt   次数   core   最小值   就是   src   ==   

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

package aa;
import java.util.Scanner;
public class Wyy {
    public static void main(String[] args) {
        // TODO Auto-generated method stub    
        Scanner sc=new Scanner(System.in);
         int [] a=new int [10];
         int c=0;
         for(int i=0;i){     
           System.out.print("请第"+(i+1)+"位评委打分:");
           int b=sc.nextInt();
              if(b>=0 && b){
               a[i]=b;
               c=c+b;
              }else{
               System.out.println("打分不在范围内,请重新打分");
               i--;
               continue;
              }        
         }
         int max=a[0];
         int min=a[0];
         for(int x=0;x){
          if(a[x]>max){
           max=a[x];
          }else if(a[x]min){
           min=a[x];
          }        
         }
         int n=(c-max-min)/(a.length-2);
         System.out.println("该选手的成绩为"+n);
      }
    }

技术图片

2.自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出

package aa;
import java.util.Random;
public class Wyy {
    public static void main(String[] args) {
        // TODO Auto-generated method stub    
        int arr[] = new int[10];
          Random r = new Random();
          for (int i = 0; i ) {
           arr[i] = r.nextInt(100);
          }
          for (int i = 0; i ) {
           for (int n = 0; n ) {
            if (arr[n] > arr[n + 1]) {
             int c = arr[n];
             arr[n] = arr[n + 1];
             arr[n + 1] = c;
            }
           }

          }
          for (int x = 0; x ) {
           System.out.print(arr[x] + " ");
          }
         }
        }

技术图片

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

package aa;
import java.util.Random;
public class Wyy {
    public static void main(String[] args) {
        // TODO Auto-generated method stub    
        int[] score = new int[7];
        Random r = new Random();
        for (int i = 0; i )
        {
            score[i] = r.nextInt(35) + 1;
        }
        System.out.println("35选7号码为:");
        for (int i = 0; i )
        {
            System.out.print(score[i]+" ");
        }
    }
}

技术图片

4.定义一个长度为10的int数组,统计数组中的最大值、最小值、以及奇数和偶数的个数

package aa;
public class Wyy {
    public static void main(String[] args) {
        // TODO Auto-generated method stub    
        int max=0,min=99;
          int os=0,js=0;
          int []a={99,45,23,66,12,30,65,26,8,44};
          for (int i = 0; i ) {
           if (a[i] min) {
            min = a[i];
           }
           if (a[i] > max) {
                     max = a[i];
                    }
          }
          for (int i = 0; i ) {
           if (a[i]%2==0) {
            os++;    
           }else{
            js++;
           }
          }
          System.out.println("偶数出现的次数:" + os);
          System.out.println("奇数出现的次数:" + js);
          System.out.println("最大值:" + max);
          System.out.println("最小值:" + min);
         }
        }

技术图片

JAVA第七周上机练习

标签:col   pac   alt   次数   core   最小值   就是   src   ==   

原文地址:https://www.cnblogs.com/jisuanji-04/p/12711975.html


评论


亲,登录后才可以留言!