5.1 “学生”类:
² 类名:Student
² 属性:姓名、性别、年龄、学号、5门课程的成绩
² 方法1:在控制台输出各个属性的值、
² 方法2:计算平均成绩
² 方法3:输出各个属性的值和平均成绩
package hellojava;
public class student {
private String name;
private String sex;
private int age;
private String num;
public static void main(String[] args) {
student x=new student(); student y=new student();
x.name="甲";
x.sex="男";
x.age=19;
x.num="201804516113";
System.out.println("姓名:"+x.name+"性别:"+x.sex+"年龄:"+x.age+"学号:"+x.num+"");
System.out.println("\n");
int score1[]=new int[]{88,78,97,95,86};
int s=0;
for(int i=0;i<5;i++){
s=s+score1[i];
System.out.println("成绩为:"+score1[i]);
}
System.out.println("平均分为:"+s/5);
y.name="乙";
y.sex="女";
y.age=20;
y.num="201801420266";
System.out.println("姓名:"+y.name+"性别:"+y.sex+"年龄:"+y.age+"学号:"+y.num+"");
int score2[]=new int[]{94,87,79,87,100};
float j=0;
for(int i=0;i<5;i++){
j=j+score2[i];
System.out.println("成绩为:"+score2[i]); }
System.out.println("平均分为:"+j/5);
}
}
java第三次上机
原文:https://www.cnblogs.com/0426abc/p/10770816.html