题解 | #实现接口#

实现接口

https://www.nowcoder.com/practice/b47b04275f7e4fa588221f03b2527d4d

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Comparator comparator = new ComparatorImpl();

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            System.out.println(comparator.max(x, y));
        }
    }

}

interface Comparator {
    /**
     * 返回两个整数中的最大值
     */
    int max(int x, int y);
}

//write your code here......
class ComparatorImpl implements Comparator{
    @Override
    public int max(int x, int y){
        x = Math.max(x,y);
        return x; 
    }
}

全部评论

相关推荐

头像
09-25 12:08
已编辑
门头沟学院 C++
罗格镇的小镇做题家:我投了hr打电话来说学历太低了不符合要求,建议投荣耀,结果荣耀也投了一定水花没有,非本211硕
投递华为等公司10个岗位
点赞 评论 收藏
分享
最讨厌装boyi的二🔥:服从性测试😉
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务