-2

I have searched high and low through your website but cannot find the answer I am looking for. Apologies if this has been asked before, I am a total noob to java and programming in general so don't really know where to look any way I am having a problem with the following code. I compile the following code

and it tells me that it cannot find the symbol "a"

import java.util.Scanner;

public class Trees {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Please enter the grade:");
        String grade = in.nextLine();

        if (grade == a) {
            System.out.println("range for a");
        }
    }
}

and this is the error message that I am getting.....

C:\Users\cawle\Desktop\itbyr1\fundamentals of programming\lab 05\Trees.java:15: error: cannot find symbol
if(grade == a)
            ^
  symbol:   variable a
  location: class Trees
1 error

I have been stuck on this for hours, any help would be greatly appreciated.thanks in advance.

E_p
  • 3,136
  • 16
  • 28

1 Answers1

3

You have not defined any variable named 'a' in your code. I suppose you just want to compare the 'grade' value entered by user to the literal 'a'. In that case you should change your 'if' statement to following:

if(grade.equalsIgnoreCase("a")