-3

Why the declaration of x variable does not work? It shows error : cannot find symbol I am new to Java programming

public static void CompareMark() {
    double x;
    System.out.print("Enter mark: \n");
    x = scan.nextDouble();
    if (x >= 0 && x <= 100) {
        if (x >= 0 && x <= 49)
            System.out.println("Grade:F");
        else if (x >= 50 && x <= 59)
            System.out.println("Grade:C");
        else if (x >= 60 && x <= 74)
            System.out.println("Grade:B");
        else
            System.out.println("Grade:A");
    } else
        System.out.println("Invalid marks");
}
ernest_k
  • 42,928
  • 5
  • 50
  • 93
323 Kobby
  • 63
  • 1
  • 5

2 Answers2

0

You haven't declared scan:

Scanner scan = new Scanner(System.in);
this_is_cat
  • 138
  • 10
0
import java.util.Scanner;

public class Testing {

    public static void main(String[] args) {
        compareMark();
    }

    public static void compareMark() {
        double x;
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter mark: \n");
        x = scan.nextDouble();
        if (x >= 0 && x <= 100) {
            if (x >= 0 && x <= 49)
                System.out.println("Grade:F");
            else if (x >= 50 && x <= 59)
                System.out.println("Grade:C");
            else if (x >= 60 && x <= 74)
                System.out.println("Grade:B");
            else
                System.out.println("Grade:A");
        } else
            System.out.println("Invalid marks");
    }
}
kavita
  • 367
  • 2
  • 7