i have the following problem:
I need to ask the user if he wants to do a addition or subtraction.
I am using the Scanner class to ask for the Input. That works well for the numbers, he prints the question and waits for input. But as soon as i try to use the Scanner for a String (do you want + or -) it just jumps over it.
Code bit:
Scanner sc= new Scanner(System.in);
System.out.print("enter number 1: ");
double num1= sc.nextDouble();
System.out.print("enter number 2: ");
double num2= sc.nextDouble();
System.out.print("plus (+) oder minus(-)?: ");
String operator= sc.nextLine();
After that i have a if loop that either adds or subtracts num1 and num2.
If i run the code i do not get the chance to do an input at String operator= sc.nextLine();, it just ends the problem with the else part of my if loop.
Same problem if i just take out the if loop.