Skip to content
Advertisement

how to fix cannot resolve symbol and variable never used, errors

I am new to java and this is my first program, I’m very confused with these errors and have looked everywhere for the answer. please help!

JavaScript

Then it gives me these errors, I’m using IntelliJ idea

JavaScript

Advertisement

Answer

Cannot resolve symbol ‘ans’

Declare ans outside the if:

JavaScript

otherwise it is never visible in the line where it is used in System.out.println

Variable ‘ans’ is never used

Variable ‘ans’ is never used

In your code ans is declared in the if – code blocks, and after assignment those ans are no longer used, because code-block in if ends just after the assignment.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement