try
{
if (expr.contains("+"))
{
return (Integer.parseInt(left) + Integer.parseInt(right)).toString();;
}
else if (expr.contains("*"))
{
return (Integer.valueOf(left) * Integer.valueOf(right)).toString();
}
else if (expr.contains("-"))
{
return (Integer.parseInt(left) - Integer.parseInt(right)).toString();
}
else
{
return (Integer.parseInt(left) / Integer.parseInt(right)).toString();
}
}
catch (java.lang.Exception e)
{
}
Am trying to do operations on integers,then, convert int to string but am getting int cannot be dereferenced error.
Integer.parseInt(left) - Integer.parseInt(right) is an int. An int is a primitive, so it has no methods, therefore you can't call toString() on an int value.
You can use the static Integer.toString() method instead.
For example:
return Integer.toString(Integer.parseInt(left) - Integer.parseInt(right));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With