Your sum is all within the code block and belongs to local variables. A code block corresponds to a method body, and local variables are only valid in the corresponding method body.
To make line 55 effective, define a global variable sum before line 39
After modifying the program source code, you need to click Run to compile it once, because the program executes the compiled file