WA代码:(类)
/*
* java 用类来实现结构体数组功能******
*/
import java.util.Scanner;
public class Main {
public static class people{//类 抽象
int score[];
String name;
}
public static void main(String args[]){
Scanner input=new Scanner(System.in);
people stu;//对象 具体
while(input.hasNext()){
int max,min,i,sum=0;
for(i=1;i<=7;i++){
stu=new people();
//没有这部分,则The local variable stu may not have been initializ
stu.score[i]=input.nextInt();
sum+=stu.score[i];
}
stu=new people();//初始化?
stu.name=input.nextLine();
max=min=stu.score[1];
for(i=2;i<=7;i++){
if(max<stu.score[i]) max=stu.score[i];
if(min>stu.score[i]) min=stu.score[i];
}
sum-=max-min;
double ave=sum/5.00;
System.out.print(stu.name+" ");
System.out.printf("%.2f",ave);
}
}
}
AC代码:(对于字符串,区分next()与nextLine()的区别******)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
double max, min;
int i;
double a[] = new double[9];
while (input.hasNext()) {
double sum = 0;
for (i = 1; i <= 7; i++) {
a[i] = input.nextDouble();
sum += a[i];
}
//input.next();//吃掉空格
String name = input.next();//用nextLine会PE
max = min = a[1];
for (i = 2; i <= 7; i++) {
if (max < a[i])
max = a[i];
if (min > a[i])
min = a[i];
}
sum = sum - max - min;
double ave = sum / 5.00;
System.out.print(name + " ");
System.out.printf("%.2f", ave);
System.out.println();
}
}
}