第三次上机

it2025-11-06  2

5.1 “学生”类:

²   类名:Student

²   属性:姓名、性别、年龄、学号、5门课程的成绩

²   方法1:在控制台输出各个属性的值、

²   方法2:计算平均成绩

²   方法3:输出各个属性的值和平均成绩

package student;import java.util.*;public class student { static String name; static String sex; static int age; static String num; static float score; static float average; static void a() { System.out.println("姓名:"+name+"\n"+"性别:"+sex+"\n"+"年龄:"+age+"\n"+"学号:"+num); } public static void main(String[] args) { student a=new student(); Scanner reader=new Scanner(System.in); System.out.println("请输入姓名:"); a.name=reader.next(); System.out.println("请输入性别:"); a.sex=reader.next(); System.out.println("请输入年龄:"); a.age=reader.nextInt(); System.out.println("请输入学号:"); a.num=reader.next(); float S=0; for(int i=0;i<5;i++) { System.out.println("请输入成绩:"); a.score=reader.nextInt(); S=S+score; System.out.println("成绩为:"+score); } average=S/5;}}

转载于:https://www.cnblogs.com/YShen0/p/10771359.html

相关资源:大连理工大学-编译技术-第二次上机
最新回复(0)