7-2 jmu-Java-02基本语法-06-枚举 (3 分)

基础题目第二道

以下是AC代码。

这道题目绝对的恶心,集美大学NB

铁子们,帮忙点个赞啊。

import java.util.*;
import java.io.*;
enum Grade {
    A,B,C,D,E;
    public String name;
    public Grade getGrade(int s) {
        int t ;
        t = s/10;
        Grade g;
        switch (t)
        {
        case 10:
        case 9:
            System.out.println("Excellent");
            g = Enum.valueOf(Grade.class,"A");
            break;
        case 8:
            System.out.println("Good");
            g = Enum.valueOf(Grade.class,"B");
            break;
        case 7:
            System.out.println("Average");
            g = Enum.valueOf(Grade.class,"C");
            break;
        case 6:
            System.out.println("Fair");
            g = Enum.valueOf(Grade.class,"D");
            break;
        default:
            g = Enum.valueOf(Grade.class,"E");
            System.out.println("Poor");

        }
        return g;
    }
}

public class Main
{
    public static void printGradeInfo(Grade grade) {
        System.out.println("class name="+Grade.class);
        System.out.println("grade value="+grade);
    }
	static int cnt =0;
	public static void main(String []args){
		int t ;
		Scanner s = new Scanner(System.in);
		while (true)
		{
		
			String ss ;
			
			ss = s .next();
			if (ss.equals(""))
			{
				break;
			}
			else {
				t = Integer.parseInt(ss);
				Grade g=Enum.valueOf(Grade.class,"A") ;
				g=g.getGrade(t);
			//	System.out.println(cnt);
				printGradeInfo(g);
			}
		}
	}
}

 

你可能感兴趣的:(JAVA)