gpt4 book ai didi

java - 我想用jsp将随机数据添加到html中的表中

转载 作者:行者123 更新时间:2023-12-02 06:02:48 25 4
gpt4 key购买 nike

我在做网络开发作业时遇到了困难,因为我对 Java 的了解不够。这看起来很容易,但对我来说这并不是什么困难的任务。我想解释一下。

我的代码将生成 5 个随机数,然后将它们作为列表显示在页面上。生成的每个数字都在 1 到 100 之间,并且有一个变量名称。之后,代码将生成一个 4 列 5 行的表格。生成数字的变量名称将随机写入前两列。在第三列中,将出现随机数学运算。在第四列中将显示结果。之后,您将自己创建一个数学函数,并将结果作为参数提供给该函数,代码将计算该函数的结果,并对结果应用 mod 10。最终结果将显示给用户。下面有10个链接,标记为0到9。如果用户点击正确的链接,则页面将导航到您自己的个人页面,否则用户将被重定向到显示结果错误的页面.

taskimage

    <h2>Random Table</h2>
<TABLE>
<% for(int row=1; row <= 5; row++) { %>
<TR>

<%
List<Integer> sayilar1 = new ArrayList<Integer>();

int random = (int)(Math.random() * 50);
sayilar1.add(random);

%>
<TD> (<%=random%>)
</TD>
<% } %>

<% for(int row2=1; row2 <= 5; row2++) { %>
<%
List<Integer> sayilar2 = new ArrayList<Integer>();
int random2 = (int)(Math.random() * 50);
sayilar2.add(random2);
%>
<TD>
<%=random2%>
</TD>
<% } %>
</TR>
</TABLE>

最佳答案

鉴于这是一项作业,我不确定我能否完全帮助您,但我可以帮助您开始。

您的代码显示为每一行打印一个值的结果。

你想要类似图片的东西,我就这样设置。

<%@ page import ="java.util.Random" %>

<html>
<head>
<title>Hello World</title>

<style>
table,th,td{
border: 1px solid #000;
}
</style>
</head>
<body>

<%
Random rand = new Random();

// Create a collection of operations
// Create a collection of variable names
%>

<h2>Random table</h2>
<table>
<tr>
<th>First var</th>
<th>Second var</th>
<th>Operation</th>
<th>Result</th>
</tr>
<% for(int row=1; row <= 5; row++) { %>
<tr>
<td>
<% /* Random variable name goes here */ %>
</td>
<td>
<% /* Random variable name goes here */ %>
</td>
<td>
<% /* Random operations goes here */ %>
</td>
<td>
<% /* Random result goes here */ %>
<% /* Hint... use rand.nextInt(maxValue) */ %>
</td>
</tr>
<% } %>
</table>
</body>
</html>

如果您需要一些说明,请告诉我。 :)

关于java - 我想用jsp将随机数据添加到html中的表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55962087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com