编写程序newclass2.jsp,学会在声明中定义类student,初始化该类(学号、姓名、成绩),用表格形式输出“学号、姓名、成绩”
时间: 2024-06-03 14:08:16 浏览: 54
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
<%@ page language="java" %>
<%
//定义学生类
class Student {
String id; //学号
String name; //姓名
int score; //成绩
public Student(String id, String name, int score) {
this.id = id;
this.name = name;
this.score = score;
}
}
//初始化学生对象
Student stu1 = new Student("001", "张三", 90);
Student stu2 = new Student("002", "李四", 85);
Student stu3 = new Student("003", "王五", 95);
//创建学生数组
Student[] students = {stu1, stu2, stu3};
%>
<html>
<head>
<title>学生信息</title>
</head>
<body>
<table border="1">
<tr>
<th>学号</th>
<th>姓名</th>
<th>成绩</th>
</tr>
<% for (Student student : students) { %>
<tr>
<td><%= student.id %></td>
<td><%= student.name %></td>
<td><%= student.score %></td>
</tr>
<% } %>
</table>
</body>
</html>
阅读全文