• 2020-07-30日报博客


    2020-07-30日报博客

    1.完成的事情:

    • 完成CodeGym Java核心 level 11部分,并完成练习题

    2.遇到的问题:

    • OOP的具体定义。

    3.明日计划:

    • 继续学习Java。
    /*taskKey="zh.codegym.task.task11.task1123"
    
    最小和最大
    
    编写返回数组的最小和最大数字的方法。
    
    
    Requirements:
    1.	程序不得从键盘读取数据。
    2.	不要更改 Pair 类。
    3.	不要更改 main 方法。
    4.	完成编写 getMinimumAndMaximum 方法。它必须返回一个包含最小值和最大值的对。
    5.	程序必须返回正确的结果。
    6.	getMinimumAndMaximum() 方法不应修改 inputArray 数组。*/
    
    
    package zh.codegym.task.task11.task1123;
    
    public class Solution {
    
        public static void main(String[] args) throws Exception {
            int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
    
            Pair<Integer, Integer> result = getMinimumAndMaximum(data);
    
            System.out.println("最小值为 " + result.x);
            System.out.println("最大值为 " + result.y);
        }
    
        public static Pair<Integer, Integer> getMinimumAndMaximum(int[] array) {
            if (array == null || array.length == 0) {
                return new Pair<Integer, Integer>(null, null);
            }
            int max = array[0], min = array[0];
            for (int i = 0; i < array.length; i++) {
                if (array[i] > max){
                    max = array[i];
                }
                if (array[i] < min){
                    min = array[i];
                }
            }
    
            return new Pair<Integer, Integer>(min, max);
        }
    
        public static class Pair<X, Y> {
            public X x;
            public Y y;
    
            public Pair(X x, Y y) {
                this.x = x;
                this.y = y;
            }
        }
    }
    
    /*taskKey="zh.codegym.task.task11.task1122"
    
    拯救国际象棋俱乐部
    
    在每种象棋类中添加共同基础类 ChessPiece。
    
    
    Requirements:
    1.	在 Solution 类中添加 public ChessPiece 类。
    2.	King 类必须继承 ChessPiece 类。
    3.	Queen 类必须继承 ChessPiece 类。
    4.	Rook 类必须继承 ChessPiece 类。
    5.	Knight 类必须继承 ChessPiece 类。
    6.	Bishop 类必须继承 ChessPiece 类。
    7.	Pawn 类必须继承 ChessPiece 类。*/
    
    
    package zh.codegym.task.task11.task1122;
    
    /* 
    拯救国际象棋俱乐部
    */
    
    public class Solution {
        public static void main(String[] args) {
        }
        public class ChessPiece {
    
        }
    
        public class King extends ChessPiece {
        }
    
        public class Queen extends ChessPiece {
        }
    
        public class Rook extends ChessPiece {
        }
    
        public class Knight extends ChessPiece {
        }
    
        public class Bishop extends ChessPiece {
        }
    
        public class Pawn extends ChessPiece {
        }
    }
    
  • 相关阅读:
    mysql 中将汉字(中文)按照拼音首字母排序
    数据库连接客户端 dbeaver 程序包以及使用说明
    maven 项目在 tomcat 中启动报错:Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    iPadOS 更新日志
    iOS 更新日志
    mybatis 中 if else 用法
    Chrome 地址栏如何设置显示 http/https 和 www
    Windows 常用工具 & 开发工具 & Chrome插件 & Firefox 插件 & 办公软件
    elasticsearch安装ik分词器
    js关闭浏览器
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/13451016.html
Copyright © 2020-2023  润新知