package cn.edu.bit.cs;
import java.util.Scanner;
public class JudgeGrade {
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
try
{
int grade=in.nextInt();
if(grade>0&&grade<60)
{
System.out.println("不及格");
}
else if(grade>=60&&grade<70)
{
System.out.println("及格");
}
else if(grade>=70&&grade<80)
{
System.out.println("中");
}
else if(grade>=80&&grade<90)
{
System.out.println("良");
}
else if(grade>=90&&grade<=100)
{
System.out.println("優");
}
else
{
throw new Exception();
}
}
catch (Exception e)
{
System.out.println("輸入錯誤");
}
}
}
1、Java輸入輸出,利用scanner類處理,system.in處理相應的輸入
2、異常處理的基本文法注意,try-catch語句,同時注意還有finally語句