0

I'm writing a really simple Java program and for some reason it just terminates when it gets to the part where I type what operation I want it to do.

     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);
        }
 }
}

After it takes the second number, it asks for me to type one of those 4 operations; After that it just terminates. Why?

SRS
  • 1
  • 3
  • Are you sure this is right? `else if(Operation.equals("Multiplication") || Operation.equals("division"))` – Fred Larson Mar 09 '15 at 17:36
  • 1
    Maybe you didn't type in one of the recognized operations; putting an `else` at the end of that chain to show what you typed would verify this. – Scott Hunter Mar 09 '15 at 17:37
  • 3
    [Skipping nextLine() after use nextInt()](http://stackoverflow.com/questions/13102045/skipping-nextline-after-use-nextint) – Jaroslaw Pawlak Mar 09 '15 at 17:37
  • You might be interested in a [case-insensitive string comparison](http://stackoverflow.com/q/2220400/10077). – Fred Larson Mar 09 '15 at 17:38
  • Never mind. My question was already answered in Jaroslaw Pawlak's comment. Thanks for the help! – SRS Mar 09 '15 at 17:50

0 Answers0