真正简单的Java计算器程序

时间:2015-03-09 17:33:07

标签: java

我正在编写一个非常简单的Java程序,并且出于某种原因它只是在它到达我键入我希望它执行的操作的部分时终止。

     package practice;
        import java.util.Scanner;

        public class Practice4 {

    static Scanner Saish = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("Hello! I am Siricalc. I am your personal calculator app!");
        System.out.println("");
        System.out.println("Please tell me your first number.");

        int firstnum = Saish.nextInt();

        System.out.println("Thanks! Now please tell me your second number!");

        int secondnum = Saish.nextInt();

        System.out.println("Got it! I just need to to know what you need to do with your numbers:");
        System.out.println(" Type Addition, Subtraction, Division, or Multiplication.");

        String Operation = Saish.nextLine();

        if(Operation.equals("Addition") || Operation.equals("addition")){
            int sum = firstnum + secondnum;
            System.out.println("Here is the sum of your first number and your second number" + sum);
        }
        else if(Operation.equals("Subtraction") || Operation.equals("subtraction")){
            int difference = firstnum - secondnum;
            int defference = secondnum - firstnum;
            System.out.println("Here is the result of the first number minus the second number" + difference);
            System.out.println("Here is the result of the second number minus the first number" + defference);
        }
        else if(Operation.equals("Division") || Operation.equals("division")){
            System.out.println("Here is the result for your first number divided by your second number" + firstnum/secondnum);
            System.out.println("Here is the result for your second number divided by your first number" + secondnum/firstnum);
        }
        else if(Operation.equals("Multiplication") || Operation.equals("multiplication")){
            int product = firstnum * secondnum;
            System.out.println("Here is the product of your first number and your second number" + product);
        }
 }
}

在获取第二个数字之后,它要求我输入这4个操作中的一个;之后它就会终止。为什么?

0 个答案:

没有答案