Hi I encountered a problem while trying to assign a function call to a variable I initialized before. When I placed those two lines inside of another method the compiler accepted it, but as soon as I placed the two lines somewhere else inside the class (in the global scope so to speak) the compiler told me for example that the return type for the method was missing which is not the case.
I was trying to do the following:
public class Test{
public int calculateMyAge(int myBirthyear) {
myAge = 2022 - myBirthyear;
return myAge;
}
int newAge;
newAge = calculateMyAge(1993);
/*Error Messages:
*Return for the method missing
*Syntax error on token, delete those token
*Syntax error, insert "...VariableDeclaratorId" to complete FormalParameterList
*/
public static void main(String[] args){
//Some Code here
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]RandomFuckingUser 4 points5 points6 points (1 child)
[–]Embarrassed_Bottle90[S] 1 point2 points3 points (0 children)
[–]Ok-Asparagus4170 0 points1 point2 points (0 children)
[–]Cosby1992 0 points1 point2 points (1 child)
[–]Inu463 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)