zoukankan      html  css  js  c++  java
  • 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() {
            }
        }
    }
    
  • 相关阅读:
    正当防卫与互殴的界限在哪里
    [php入门] 5、初学CSS从中记下的一些基础点(For小白)
    [ZigBee] 13、ZigBee基础阶段性回顾与加深理解——用定时器1产生PWM来控制LED亮度(七色灯)
    [ZigBee] 12、ZigBee之看门狗定时器——饿了就咬人的GOOD DOG
    [ZigBee] 11、ZigBee之睡眠定时器二
    [ZigBee] 10、ZigBee之睡眠定时器
    [ZigBee] 9、ZigBee之AD剖析——AD采集CC2530温度串口显示
    [ZigBee] 8、ZigBee之UART剖析·二(串口收发)
    [php入门] 4、HTML基础入门一篇概览
    [ZigBee] 2、 ZigBee开发环境搭建
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/13451058.html
Copyright © 2011-2022 走看看