Java 如何更改我的逻辑以在jsp中打印数字?
这里我的代码运行良好,但我需要不同顺序的元素顺序。 这是我的密码Java 如何更改我的逻辑以在jsp中打印数字?,java,html,jsp,Java,Html,Jsp,这里我的代码运行良好,但我需要不同顺序的元素顺序。 这是我的密码 <body> <% out.println("<table >"); int apps = 9; double rowColumn = Math.sqrt(apps); for (double i = rowColumn; i > 0; i--) { out.println("<tr>"
<body>
<%
out.println("<table >");
int apps = 9;
double rowColumn = Math.sqrt(apps);
for (double i = rowColumn; i > 0; i--) {
out.println("<tr>");
for (double j = rowColumn; j > 0; j--) {
out.println("<td>" + apps + "</td>");
apps--;
}
out.println("</tr>");
}
out.println("</table>");
%>
</body>
0; 我——){
out.println(“”);
对于(双j=rowColumn;j>0;j--){
out.println(“+apps+”);
应用程序--;
}
out.println(“”);
}
out.println(“”);
%>
它正在按如下方式打印值:
987
654
3 2 1
但我需要以下价值观:
7 8 9
654
1 2 3
如果apps=16,则我需要按如下方式输出:
16151413
9101112
8765
1234
有谁能告诉我如何更改逻辑。试试这个,将值存储在变量中,然后在for循环后打印出来:
<body>
<%
out.println("<table >");
int apps = 16;
double rowColumn = Math.sqrt(apps);
boolean flag = true;
for (double i = rowColumn; i > 0; i--) {
String rowContent = "";
out.println("<tr>");
if(flag) flag = false;
else flag = true;
for (double j = rowColumn; j > 0; j--) {
if(flag) {
rowContent = "<td>" + apps + "</td>" + rowContent;
}
else {
rowContent = rowContent +"<td>" + apps + "</td>";
}
//out.println("<td>" + apps + "</td>");
apps--;
}
out.println(rowContent);
out.println("</tr>");
}
out.println("</table>");
%>
</body>
0; 我——){
字符串rowContent=“”;
out.println(“”);
如果(flag)flag=false;
else flag=true;
对于(双j=rowColumn;j>0;j--){
国际单项体育联合会(旗){
rowContent=”“+应用程序+“”+rowContent;
}
否则{
行内容=行内容+“”+应用程序+“”;
}
//out.println(“+apps+”);
应用程序--;
}
out.println(rowContent);
out.println(“”);
}
out.println(“”);
%>
Macro Mercuri,它的打印结果与我原来的问题打印结果相同。它没有打印所需的输出。哦,对不起,我没有看到中间一行的顺序是相反的!等一下,我更新了我的答案。如果apps=16检查此条件alsoMacro,您更新的代码正在这样打印7 9 8 4 6 5 1 3 2Macro,非常感谢您花费宝贵的时间。我知道了。