第三次上机
import java.util.*;
class student{
String name;
char sex;
int age;
String number;
double score[]=new double[5];
void printq(student s){
System.out.println("姓名:"+s.name);
System.out.println("性别:"+s.sex);
System.out.println("年龄:"+s.age);
System.out.println("学号:"+s.number);
System.out.println("五门课成绩分别是:");
for(int i=0;i<5;i++){
System.out.print(s.score[i]+" ");
}
}
double avarage(student s){
double sum=0;
for(int i=0;i<5;i++){
sum+=s.score[i];
}
return sum/5;
}
void prints(student s){
s.printq(s);
System.out.print("\n平均成绩为:");
System.out.print(s.avarage(s));
}
}
public class pcw {
public static void main(String[] args) {
Scanner read=new Scanner(System.in);
student s=new student();
System.out.println("请输入姓名、性别、年龄、学号和五门课程的成绩:");
s.name=read.next();
s.sex=read.next().charAt(0);
s.age=read.nextInt();
s.number=read.next();
for(int i=0;i<5;i++)
{
s.score[i]=read.nextDouble();
}
s.prints(s);
}
}