题解 | #重写计算逻辑#

重写计算逻辑

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

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            Sub sub = new Sub(x, y);
            sub.calculate();
        }
    }

}

class Base {

    private int x;
    private int y;

    public Base(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public void calculate() {
        System.out.println(getX() * getY());
    }

}

class Sub extends Base {

    //write your code here......
    public Sub(int x, int y){
        super(x, y);
    }
    @Override
    public void calculate(){
        if(getY() == 0){
            System.out.println("Error");            
        }else {
            System.out.println(getX() / getY());
        }
        
    }
    

}

全部评论

相关推荐

FOX2003:还没学后端框架吧,看你第一个项目用的mockjs。第一个项目太老而且可能是从github上扒的(我的课设就是这个),第二个主要依靠AI的能力,而且前端项目找前端实习的话,留个github地址好点,主要还是前端要求越来越高了。另外,去***看看,符合就投,boss投的多,HR工作量就大,没功夫多聊
点赞 评论 收藏
分享
字节跳动冲冲冲冲:随时都可以投,9 10和2 3月份比较好找
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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