java - 绘制表格 10x10 并在表格中显示素数
问题描述
需要这样显示:
1 2 3 4 5
6 7 8 9 10
但我得到
1 2 3 4 5 6 7 8 9 10
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Table of prime numbers</title>
<style>
.chess-board {border-collapse: collapse; position:absolute; left: 640px; top: 240px;}
.chess-board td { border: 1px solid; width: 2em; height: 2em; }
.chess-board .light { background: #eee; }
</style>
</head>
<body>
<table class="chess-board">
<tbody>
<%
int i,count;
for(int j=2;j<=541;j++)
{
count=0;
for(i=1;i<=j;i++)
{
if(j%i==0)
{
count++;
}
}
if(count==2)
%>
<tr></tr>
<td class="light"><%out.print(j);%></td>
<%
}
%>
</tbody>
</table>
</body>
</html>
我需要在 10x10 表中显示素数
但结果我得到了这个,一切都在一行中
解决方案
生成的 html 将如下所示:
...
<tbody>
...
<tr></tr>
<td class="light">2</td>
<tr></tr>
<td class="light">3</td>
<tr></tr>
<td class="light">4</td>
...
</tbody>
...
这不是有效的 html 代码。您可以在浏览器中使用“查看源代码”或“检查”以将结果查看为 html。它应该是这样的:
...
<tbody>
...
<tr>
<td class="light">2</td>
<td class="light">3</td>
...
</tr>
<tr>
<td class="light">12</td>
<td class="light">13</td>
...
</tr>
...
</tbody>
尝试修改您的代码,使其生成那种 html。...
推荐阅读
- java - 如何在 JTable 中使 JButton 可点击
- sql - 如何从列值中删除 [] 和 ""
- matlab - Matlab中的积分
- performance - 地图有什么区别
和 {[index: string]: MyObject} 在 TypeScript 中? - sql - 是否可以对来自不同行的值求和,然后在 ms 访问时将它们合并为一行?
- android - 使用导航组件时,片段 savedInstanceState 始终为空
- c++ - 在 C++ 中的赋值遇到一些麻烦
- google-maps - 如何打印几个标记google map api 0.5.7 Flutter
- python - 保留字典键的顺序
- javascript - 一旦页面被重定向到同一网站上的另一个页面,如何显示预加载器 GIF?