题解 | #实现接口#

实现接口

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);
}
class ComparatorImpl implements Comparator{
    public int max(int x,int y){
        return x>y?x:y;
    }
}

//write your code here......

java相关 文章被收录于专栏

java刷题,或许会有其他方面

全部评论

相关推荐

ddd7_:跟我一模一样,加微信的hr都同一个,扫码了白年书人查看图片
点赞 评论 收藏
分享
11-06 23:30
已编辑
华中师范大学 后端工程师
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务