'Keep getting "Java error: cannot find symbol" when using input.getInt
I am trying to make a basic calculator but I keep getting this error message. I have looked on the internet but nothing seem to help me.
I am not sure whether the program is having trouble or if I have misplaced something in the brackets.
Here are my error messages:
Main.java:9: error: cannot find symbol
int num1 = input.nextInt;
^
symbol: variable nextInt
location: variable input of type Scanner
Main.java:12: error: cannot find symbol
int num2 = input.nextInt;
^
symbol: variable nextInt
location: variable input of type Scanner
Main.java:15: error: cannot find symbol
char operation = input.next().CharAt0();
^
symbol: method CharAt0()
location: class String
3 errors
Here's my code:
import java.util.Scanner;
import java.util.Scanner;
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// Gets both numbers and operator from user
System.out.println("Enter first number");
int num1 = input.nextInt;
System.out.println("Enter second number");
int num2 = input.nextInt;
System.out.println("Enter operation (+ - * /)");
char operation = input.next().CharAt0();
}
// Switch case that does calculations
static int calculate(num1, num2, operation) {
switch (operation) {
case '+':
System.out.println(num1 + num2);
break;
case '-':
System.out.println(num1 - num2);
break;
case '*':
System.out.println(num1 * num2);
break;
case '/':
System.out.println(num1 / num2);
break;
default:
System.out.println("Not a valid input");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|