62,620
社区成员
发帖
与我相关
我的任务
分享
//从控制台中读取一行输入数据
String tem = scanner.nextLine();
//使用空格将该行数据分隔
String input[] = tem.split(" ");
//用户输入的数据格式可能存在问题,所以在这里需要捕获异常
try
{
float score = Float.parseFloat(input[2]);
}
catch(NumberFormatException e)
{
System.out.println("格式错误!");
scanner.close();
return;
}