建立数学计算器时遇到问题

时间:2018-08-20 06:36:31

标签: java

我正在尝试用Java构建数学计算器,但是我遇到了问题,我想使用方法而不是int来构建它。

我在如何打印返回值(rishon + sheni)以及如何检查控制台写的in.nextLine()是否等于这样的问题上遇到问题:

    package mehadash;
    import java.util.Scanner;

    public class lilmod {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String plus = null;
        String minus = null;
        String math;
        int sum = 0;

        System.out.println("What kind of math you want to do?");
        math = in.nextLine();
        if(math = plus)
        {
            System.out.println("Enter the two numbers you would like to check");
            SumNumbers(in.nextInt(),in.nextInt());

            System.out.println("The answer is :" +SumNumbers());
        }



    minusNumbers(in.nextInt(),in.nextInt());
    }
    public static int SumNumbers(int rishon , int sheni)
    {
        return rishon + sheni;

    }
    public static int minusNumbers(int rishon , int sheni)
    {
        return rishon - sheni;
    }

}

2 个答案:

答案 0 :(得分:0)

您始终可以定义更多变量。

int numberA = in.nextInt();
int numberB = in.nextInt();


int result = SumNumbers(numberA, numberB);


System.out.println("The result: " + result);

答案 1 :(得分:0)

  

如何打印返回值(rishon + sheni)

尝试这种方式:

System.out.println("The answer is :" +SumNumbers(in.nextInt(),in.nextInt()));

代替

SumNumbers(in.nextInt(),in.nextInt()); 
System.out.println("The answer is :" +SumNumbers());
  

还如何检查in.nextLine();控制台写的相等   加上

尝试

if(math.equals("+"))

代替

if(math = plus)