Identifier expected

+2 Arnab Banerjee · January 24, 2015
import java.util.*;
static int grade;
public class{
public static void main(String args[]){
System.out.println(" Enter your grade ");
Scanner input = new Scanner(System.in);
grade = input.nextInt();

switch(grade){
case 9:
System.out.println("Out standing");
break;
case 8:
System.out.println("Excellent");
break;
case 7:
System.out.println("Very good");
break;
case 6:
System.out.println("Good");
break;
case 5:
System.out.println("Satisfactory");
break;
default:
System.out.println("Failed");

}
}
}

What's wrong in this code ? :P 

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
+1 Neil Cannon · January 24, 2015
import java.util.Scanner;
public class Prog3{
    static int grade;
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter your grade ");
        grade = input.nextInt();
            
        if(grade <=4){
            System.out.println("Fail!");
            }
        
        else if (grade >=5 && grade <6) {
            System.out.println(" Satisfactory");
            }
            
        else if (grade >=6 && grade <7) {
            System.out.println("Very Good");
            }
    
        else if (grade >=7 && grade <8) {
        System.out.println("Excellent");
            }
    
        else if (grade >=8 && grade <9) {
        System.out.println("Out Sounding");
            }
    
        else
        System.out.println("Genius ");
        
            input.close();
    }
}

/// or using if else ///
0 Necip Asım Arslan · January 24, 2015
Hi,

I examined your code I found a few errors in it:


package learn;

import java.util.*;

    public class test{ //You need to give a name your class
        
    static int grade; // You need to define your static variable in a class

        public static void main(String args[]){
            System.out.println(" Enter your grade ");
            Scanner input = new Scanner(System.in);
            grade = input.nextInt();
            input.close();  //also you need to close your scanner in case of leak
            
            switch(grade){
                case 9:
                System.out.println("Out standing");
                break;
                case 8:
                System.out.println("Excellent");
                break;
                case 7:
                System.out.println("Very good");
                break;
                case 6:
                System.out.println("Good");
                break;
                case 5:
                System.out.println("Satisfactory");
                break;
                default:
                System.out.println("Failed");
                
            }
        }
    }


Sorry for bad English.
And I'm a beginner in java I would like to remind.
  • 1
  • 2

Java / Android Development

107,214 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator