Hello everyone.
I am having problems compiling my Java Code.. I am presuming it is because of a casting/promotinng error in the second method "method1".
If anyone could spot the errors and let me know that would be great!
Thank you in advance
Hello everyone.
I am having problems compiling my Java Code.. I am presuming it is because of a casting/promotinng error in the second method "method1".
If anyone could spot the errors and let me know that would be great!
Thank you in advance
Whenever you define a new variable, it is 'available' within some scope. For the vast majority of java variable definitions, that scope is 'lexical': Look for the nearest enclosing pair of brackets. Within that, it is visible. Outside, it does not exist.
On line 22 you define variable n1: int n1 = ...
;. The nearest braces are on line 21 through at least 40 (the screenshot isn't wide enough) – certainly not line 12, where you reference it. So, at line 12, n1 simply does not exist. at all. That's one error explained.
Another is line 24: Line 23 returns. There is no way for the code to continue execution after that, and javac won't let you compile this: Line 24 is erroneous in that it is impossible to reach. I don't know how to fix it because your code is not clear; I don't know what you are trying to do here.
Perhaps you think 'return' is like 'export'; that's.. just not how it works. return returns from the method. Execution stops right then and there in that method and swaps back to the caller, and the method's value is whatever the expression you supply to the return statement calculates to.
It feels like you want to return 3 separate values from the method. That's not how java works: You can return only one. You can make this some sort of object (an array, or a new instance of a class you write) and in that way effectively 'return multiple values', but you have to package them up into a single thing to return.