问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int sum = 0;
Cla cc = new Cla();
cc.num = 0;
while(sc.hasNext()){
Student s = new Student();
s.name = sc.next();
s.id = sc.next();
s.sex = sc.next();
s.age = sc.nextInt();
cc.stu[cc.num] = s;
sum +=cc.stu[cc.num].age;
cc.num ++;
}
double avg = (double)sum/ (double)cc.num;
System.out.println("班级学生"+cc.num+"人,平均年龄"+ String.format("%.1f",avg) +".");
}
}
class Student{
String name;
String id;
int age;
String sex;
}
class Cla{
Student[] stu = new Student[100];
int num;
}
才学Java几天,不知道怎么做了