题解 | #修改Data类的定义#

修改Data类的定义

http://www.nowcoder.com/practice/bb89f943588c4a248675881f2e5cc761

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();
            Data data = new Data(x, y);
            System.out.println(data.getX() + data.getY());
        }
    }
    //创建内部类和构造方法
    static class Data{
        private int x;
        private int y;
        public Data(int x, int y) {
        this.x = x;
        this.y = y;
    }

    private int getX() {
        return x;
    }

    private int getY() {
        return y;
    } 
    }

}


全部评论

相关推荐

11-17 14:18
门头沟学院 C++
代码飞升_不回私信人...:这种感觉还好。只是你写一个PPT,可能他面的快一点而已。那种让你写什么方案,写什么代码的那种。就没必要去了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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