What variable type should I use?
I want to make a simple calculator. The user enters two numbers and then has a choice of either adding or subtracting them. Here is the code:
Code:
import java.util.Scanner;
class apples {
public static void main(String[] args){
double firstNumber;
double secondNumber;
double answer;
char choice;
Scanner userInput = new Scanner(System.in);
System.out.println("Enter the first number: ");
firstNumber = userInput.nextInt();
System.out.println("Enter the second number: ");
secondNumber = userInput.nextInt();
System.out.println("Enter your choice (add or substract): ");
choice = userInput.nextChar();
}
}
Of course, the userInput.nextChar() is invalid. Why? What should I use instead?
Thanks :)-: