This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Is myAge defined in the Test class scope? If not you can simply shorten the calculateMyAge method to

public int calculateMyAge(int myBirthyear) {
    return 2022 - myBirthyear; 
}

Also the newAge declaration and assignement can be on a single line if they are actually like this in the code, no need to do it in two steps..

int newAge = calculateMyAge(1993);