编写程序newclass2.jsp,学会在声明中定义类student,初始化该类(学号、姓名、成绩),用表格形式输出“学号、姓名、成绩”
时间: 2024-06-03 21:08:16 浏览: 12
<%@ 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>
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)