/**
     * 求数组中的最大值
     */
    @Test
    public  void  test14(){
        //定义一个数组   参赛的选手
        int  [] nums={50,20,30,80,100,90};
        //定义一个擂主
        int max=0;
       //循环打擂
        for (int i = 0; i < nums.length; i++) {
            //如果发现 数组中的元素 大于 max  就让当前的元素的值给max
            if (nums[i]>max) {
                max=nums[i];
                System.out.println("历届的擂主::"+max);
            }
        }
        System.out.println("最终的擂主是:"+max);
    }
    /**
     * 求数组中的最小值
     */
    @Test
    public  void  test15(){
        //定义一个数组   参赛的选手
        int  [] nums={50,200,30,80,100,90};
        //定义一个最小值  默认是 数组中的第一个元素
        int min=nums[0];
        //循环打擂
        for (int i = 0; i < nums.length; i++) {
            //如果发现数组中的元素小于min 把元素的值给min
            if (nums[i]<min) {
                min=nums[i];
            }
        }
        System.out.println("最小的数值是:"+min);
    }
求数组的最大和最小值

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-12-12
  • 2022-02-27
猜你喜欢
  • 2022-02-06
  • 2021-05-16
  • 2022-12-23
  • 2021-07-27
相关资源
相似解决方案