• 2020-08-03日报博客


    2020-08-03日报博客

    1.完成的事情:

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

    2.遇到的问题:

    • 接口的定义和使用。

    3.明日计划:

    • 继续学习Java。
    /*taskKey="zh.codegym.task.task12.task1233"
    
    同形体即将来临
    
    编写返回数组的最小值及其位置(索引)的方法。
    
    
    Requirements:
    1.	Solution 类必须包含 Pair 类。
    2.	Solution 类必须包含两个方法。
    3.	Solution 类必须包含 getMinimumAndIndex() 方法。
    4.	getMinimumAndIndex() 方法必须返回数组的最小值及其位置(索引)。
    
    
    
    
    package zh.codegym.task.task12.task1233;*/
    
    /* 
    同形体即将来临
    */
    
    public class Solution {
    
        public static void main(String[] args) {
            int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
    
            Pair<Integer, Integer> result = getMinimumAndIndex(data);
    
            System.out.println("最小值为 " + result.x);
            System.out.println("最小元素的索引为 " + result.y);
        }
    
        public static Pair<Integer, Integer> getMinimumAndIndex(int[] array) {
            if (array == null || array.length == 0) {
                return new Pair<Integer, Integer>(null, null);
            }
    
            int min = array[0],t = 0;
            for (int i = 0; i < array.length; i++) {
                if(array[i] < min){
                    min = array[i];
                    t = i;
                }
            }
    
    
            return new Pair<Integer, Integer>(min, t);
        }
    
        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.task12.task1228"
    
    Human 类的接口
    
    在 Human 类中尽可能多添加接口,但要确保它不会成为一个抽象类。
    你不能在 Human 类中添加方法。
    
    
    Requirements:
    1.	Solution 类必须包含具有 void workLazily() 方法的 Employee 接口。
    2.	Solution 类必须包含具有 void workHard() 方法的 Businessman 接口。
    3.	Solution 类必须包含具有 void workLazily() 方法的 Secretary 接口。
    4.	Solution 类必须包含具有 void workVeryHard() 方法的 Miner 接口。
    5.	Solution 类必须包含具有如下方法的 Human 类:void workHard() 和 void workLazily()。
    6.	Human 类必须实现三个接口。*/
    
    package zh.codegym.task.task12.task1228;
    
    /* 
    Human 类的接口
    */
    
    public class Solution {
        public static void main(String[] args) {
            Human human = new Human();
            System.out.println(human);
        }
    
        public static interface Employee {
            public void workLazily();
        }
    
        public static interface Businessman {
            public void workHard();
        }
    
        public static interface Secretary {
            public void workLazily();
        }
    
        public static interface Miner {
            public void workVeryHard();
        }
    
        public static class Human implements Secretary,Businessman,Employee{
    
            public void workHard() {
            }
    
            public void workLazily() {
            }
        }
    }
    
  • 相关阅读:
    ActivityGroup简单介绍
    退役笔记一#MySQL = lambda sql : sql + &#39; Source Code 4 Explain Plan &#39;
    敏捷开发流程总结
    TI C66x DSP 系统events及其应用
    AssemblyInfo.cs文件的作用
    angularjs基本执行流程
    美丽的表格样式(使用CSS样式表控制表格样式)
    DOS命令大全--具体解释
    《海量数据库解决方式》读后感
    Linux内核设计基础(十)之内核开发与总结
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/13451058.html
Copyright © 2020-2023  润新知