编写程序newclass2.jsp,学会在声明中定义类student,初始化该类(学号、姓名、成绩)
时间: 2024-06-11 10:10:27 浏览: 73
<%@ page language="java" %>
<%
// 定义类student
class student {
String id; // 学号
String name; // 姓名
double score; // 成绩
// 构造方法
public student(String id, String name, double score) {
this.id = id;
this.name = name;
this.score = score;
}
// 输出信息
public void printInfo() {
out.println("学号:" + id + "<br>");
out.println("姓名:" + name + "<br>");
out.println("成绩:" + score + "<br>");
}
}
// 初始化学生信息
student s1 = new student("001", "张三", 89.5);
student s2 = new student("002", "李四", 92.0);
student s3 = new student("003", "王五", 78.5);
// 输出学生信息
out.println("<h3>学生信息列表</h3>");
s1.printInfo();
s2.printInfo();
s3.printInfo();
%>
阅读全文