0

I'm still learning Java and practicing and end up creating this code below but every time I run it in IDE Editor, it keeps being terminated console tab. Hope someone can help me,

import java.util.Scanner;
public class Practice {

public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
String response;
int x, y, total;    
    System.out.println("Input the first variable:");
    x = scan.nextInt();
    System.out.println("Input the second variable");
    y = scan.nextInt();
    System.out.println("How should we solve it?");
    System.out.println("(Add, Subtract, Multiply, Divide)");
    response = scan.nextLine();

    if (response.equals("Add")) {
        total = x + y;
        System.out.println("The sum of " + x + y + " is " + total);
    }
    else if (response.equals("Subtract")) {
        total = x - y;
        System.out.println("The difference of " + x + y + " is " + total);
    }
    else if (response.equals("Multiply")) {
        total = x * y;
        System.out.println("The product of " + x + y + " is " + total);
    }
    else if (response.equals("Divide")){
        total = x / y;
        System.out.println("The Qoutient of " + x + y + " is " + total);
    }
    
}

}

  • 3
    Does this answer your question? [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – vincrichaud Nov 17 '21 at 08:39

0 Answers0