I am very new to java and i'm trying to make a basic calculator. There is another question on this but I changed the things that fixed it for him but it still doesn't work. Here's my code:
import java.util.Scanner;
class HelloWorld{
public static void main(String args[])
int num1;
int num2;
String op;
Scanner input = new Scanner(System.in);
System.out.println("Enter your first number");
num1 = input.nextInt();
System.out.println("Enter your second number");
num2 = input.nextInt();
System.out.println("Enter the operation");
op = input.nextLine();
if (op.equals("*")){
System.out.println("The answer is: " + (num2 * num1));
}
if (op.equals("/")){
System.out.println("The answer is: " + (num2 / num1));
}
if (op.equals("+")){
System.out.println("The answer is: " + (num2 + num1));
}
if (op.equals("-")){
System.out.println("The answer is: " + (num2 - num1));
}
}
}
The error says:
Enter your first number
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at HelloWorld.main(HelloWorld.java:12)
I can't seem to find whats wrong (I have its something simple that i missed)