java 总是提示需要;

2025-03-23 13:59:00
推荐回答(5个)
回答1:

你抛异常写错了  是throws  不是throw  而且String args [] String没大写

switch case 也写错了 a<=100&&a>=90 返回的是boolean 不是int

你可以这样写

import java.io.*;
public class switch2
{
 public static void main(String args[])throws Exception
 {
 String str;
 int a;
 BufferedReader buf;
 buf=new BufferedReader(new InputStreamReader(System.in));
 str=buf.readLine();
 a=Integer.parseInt(str);

 if(a >= 90) System.out.println("优");
 else if(a >= 80) System.out.println("良");
 else if(a >= 70) System.out.println("中");
 else if(a >= 60) System.out.println("差");
 else if(a >= 0) System.out.println("无");
 }
}

回答2:

throw方式:表示手动抛出异常
throws方式:声明方法可以捕捉的异常

1、你上面的异常,在方便后面应该采用throws抛出;
2、throws与方法的右括号之间应该有空格分开;
3、main(string args[])中的string每一个字母要大写:String
4、switch语句的参数应该是int类型或可以转换成int类型的其它类型,如byte、short、char

回答3:

//希望以下代码可以帮到你。
import java.io.*;
public class Switch2
{
public static void main(String args[])throws Exception//这里的关键字,用错了throws
{
String str;
int a;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
str=buf.readLine();
a=Integer.parseInt(str);
a=a/10;
switch(a)//这里你程序的设计不符合,switch的语序规范,建议你重新看以下switch的结构。
{
case 10:
case 9:System.out.println("优");break;
case 8:System.out.println("良");break;
case 7:System.out.println("中");break;
case 6:System.out.println("差");break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:System.out.println("无");break;
default:System.out.println("input error");break;//这里如果输入的不是数字有异常,希望你能注意下。
}
}
}

回答4:

人家不是提示第四行需要;分号嘛 加个分号就是了

回答5:

string 首字母要大写