class Main {
public static void main(String args[]) {
GetScore m=new GetScore();
String score="数学87分,物理86分,英语97分";
m.getScore(score);
}
}
/* 请在这里填写答案 */
这是我写的
class GetScore {
public static void getScore(String score) { String cost ="数学87分,物理86分,英语97分";
Scanner scanner = new Scanner(cost);
scanner.useDelimiter("[^0123456789.]+");
double sum=0;
int count =0;
while(scanner.hasNext()){
try{ double a = scanner.nextDouble();
count++;
sum = sum+ a;
}
catch(InputMismatchException exp){
String t = scanner.next();
}
} System.out.print("总成绩:"+sum+";");
System.out.println("平均分数:"+sum/count);
}
}