I have this code:
kb.useDelimiter("\\b*[\\s]*");
int answer = 0;
String num1, num2;
char operator;
System.out.print("Enter calculation: "); // user will input **1+6**
num1 = kb.nextInt();
operator = kb.next().charAt(0);
num1 = kb.nextInt();
switch(operator)
{
case '+':
if (num1.hasNextInt)
{
int aa= Integer.parseInt(num1);
int bb= Integer.parseInt(num2);
answer = CalculatorMethods.add(aa,bb);
}
else
{
//converts the String into Double
}
break;
}
What im trying to do in this code is, the user can input in the program directly like this 1+1 . And what i did is i separate each so it will have 1, + and 1... and if the user inputs an integer number.... then i will convert it to an integer and then calls the method.... else it will convert the String into a double and will then call the method..
So, when i compile the code above, all i get is MANY ERRORS like incompatible types, cannot find symbol hasNextInt.... what is wrong in my code?
ANY HELP WILL BE APPRECIATED.