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 1
Oldest  Newest  Rating
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 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 ///
+1 Arnab Banerjee · January 24, 2015
Thanks Mozamel and Neil, it's working now. :) 
+1 Neil Cannon · January 24, 2015
import java.util.*;

public class Prog3{
       
    public static void main(String args[]){
        System.out.println(" Enter your grade ");
        Scanner input = new Scanner(System.in);

        int grade = 0;
        for (int i = 1; i <= 9; i++) {
        grade = input.nextInt();
        
        switch(grade){
            case 0:
            System.out.println("Embarrassing!?");
            break;
            case 1:
            System.out.println("Fail!");
            break;
            case 2:
            System.out.println("Fail!");
            break;
            case 3:
            System.out.println("Fail!");
            break;
            case 4:    
            System.out.println("Fail!");
            break;
            case 5:
            System.out.println("Satisfactory");
            break;
            case 6:
            System.out.println("Good");
            break;
            case 7:
            System.out.println("Very Good");
            break;
            case 8:
            System.out.println("Excellent");
            break;
            case 9:
            System.out.println("Out Standing");
            break;
            default:
            System.out.println("Genius");    
            
            input.close();
        
           }
            
        }
    }
}
            
        
    


//// try this code, you may want to modify ////
+1 Mr. Computer · January 24, 2015
i hope i helped :) 

let me know when its working 
0 Arnab Banerjee · January 24, 2015
Ok I am doing it. 
0 Mr. Computer · January 24, 2015
import java.util.*;
public class prog3{
public static void main(String args[])



i think the porblem is with the 

public class prog3


u have to change it with the correct name of ur main class 
0 Arnab Banerjee · January 24, 2015
no. it's saying identifier expected. 
+1 Mr. Computer · January 24, 2015
Error: Could not find or load main class apples


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

switch(grade){
case 10:
System.out.println("You got Full grade");
break;
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");

}
}
}

Still not working, feeling confused.  :'( .
  • 1
  • 2

Java / Android Development

107,039 followers
About

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

Links
Moderators
Bucky Roberts Administrator