首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >对象之间的Java OOP功能

对象之间的Java OOP功能
EN

Stack Overflow用户
提问于 2018-09-17 02:47:18
回答 1查看 96关注 0票数 -2

我在解决练习时遇到了问题

在本练习中准备了两个类: ObjectFunctionality和

。您的任务是创建Printer类,它向用户请求两个整数,调用Calculator类的Sum()方法,将输入的整数传递给该方法。方法Sum()计算这些数字的和并返回结果。最后,Sum()在屏幕上打印出总和。

import java.util.Scanner;


public class ObjectFunctionality {
    public static void main(String args[]) {
        Printer thing = new Printer();
        thing.Print();
    }
}

//  Write the missing class here
//  Class is written in the text box below.

class Calculator {
    static int Sum(int first, int second) {
        int sum = first + second;
        return sum;
    }
}

下面是我的代码:

class Printer {
        Scanner input = new Scanner(System.in);
    System.out.print("Type in the first integer: ");
    int first = reader.nextInt();
    System.out.print("Type in the second integer: ");
    int second = reader.nextInt();


    System.out.print("Sum of the numbers: " + sum.sum);


}

我知道有些事情很不对劲,但我解决不了这个问题。

PS。我需要这样的输出:

输入第一个整数:输入第二个整数:-1数字的总和:-4

非常感谢!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52357355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档