题解 | #修改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());
    }
}

}

class Data {

private int x;
private int y;

public Data(int x, int y) {
    this.x = x;//this字段将成员变量和局部变量联系在一起
    this.y = y;
}

public int getX() {
    return this.x;
}

public int getY() {
    return this.y;
}

}

全部评论

相关推荐

大佬们,在大厂实习的都是几百一天???
哈尔滨的移动城堡_:那几个有名的大厂都是300-400,小厂有更高的
点赞 评论 收藏
分享
真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
牛客383479252号:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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