其他分享
首页 > 其他分享> > 2020.4.16

2020.4.16

作者:互联网





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

import java.util.*;

public class sssa {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Random r=new Random ();

        int []arr=new  int [10];

        for (int i = 0; i < arr.length; i++) {

            arr[i]=r.nextInt(100);

        }

        for (int i = 0; i < arr.length; i++) {

            System.out.print(arr[i]+" ");

        }

        int max=0,min=arr[0],jishu=0,oushu=0;

        for (int i = 0; i < arr.length; i++) {

            if(max<arr[i])

                max=arr[i];

        }

        for (int i = 0; i < arr.length; i++) {

            if(arr[i]<min)

                min=arr[i];

        }

        for (int i = 0; i < arr.length; i++) {

            if(arr[i]%2==0)

                oushu+=1;

            else

                jishu+=1;

        }

        System.out.println("max="+max+",min="+min);

        System.out.println("奇数个数"+jishu+",偶数个数"+oushu);
    }

 

}

 

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

import java.util.Random;

public class sssa {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Random r=new Random ();

        int []arr=new  int [10];

        for (int i = 0; i < arr.length; i++) {

            arr[i]=r.nextInt(100);

        }

        for (int i = 0; i < arr.length; i++) {

            for (int j = 0; j < arr.length-i-1; j++) {

                if(arr[j]>arr[j+1]){

                    int h=arr[j];

                    arr[j]=arr[j+1];

                    arr[j+1]=h;

                }

            }

        }

        for (int i = 0; i < arr.length; i++) {

            System.out.println(arr[i]);

        }

    }

 

}

 
    
            

 

//1.有10个评委打分,(去掉一个最高一个最低)求平均分。
package jn;

import java.util.*;

public class sssa {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Scanner input=new
        Scanner (System.in);

        int [] arr= new  int [10];

        int sum=0;

        System.out.println("请输入成绩");

        for (int i = 0; i < arr.length; i++) {

            System.out.print(i+1+":");

            arr[i]=input.nextInt();

             

        }

        for (int i = 0; i < arr.length; i++) {

            for (int j = 0; j < arr.length-i-1; j++) {

                 

                if(arr[j]>arr[j+1]){

                    int h=arr[j];

                    arr[j]=arr[j+1];

                    arr[j+1]=h;

                    }

            }

        }

         

        for (int i = 1; i < 9; i++) {

            sum+=arr[i];

             

        }

         

        System.out.println("选手分数平均值为"+sum/8.0);

    }

 

}

 

标签:arr,16,2020.4,++,System,int,length,public
来源: https://www.cnblogs.com/yyyyym/p/12712355.html