First off, the code works just fine and the output is 100 in my case, just tried in VS Code. So, show the code that is causing the problem.
Now, for the question, these two errors are different,
sample.java:7: error: cannot find symbol
and,
error has occure while converting string to integer
They both have a different meaning, thus sharing that they occur at 2 different instances. The first one, would mostly mean that you might be missing an
import. Whereas, the second one meaning that you has passed in an in correct value of string, that cannot be mapped to a valid integer. A few things you can do,
int value;
try {
value = Integer.parseInt(s);
} catch (Exception e) {
}
This will ensure that incase there is a runtime exception during conversion, your app will not crash, instead will be given an opportunity to render a friendly message on the screen. If you try to check the documentation for the parseInt() function, you will see that it throws
NumberFormatException
, that is what you need to look for.
Integer (Java Platform SE 7 )[
^]