【问题标题】:how to add in a loop for string and int in java如何在java中添加字符串和int的循环
【发布时间】:2020-08-19 13:35:09
【问题描述】:

我有这个代码:

int[] arr = new int[] {0254,0156,0641,0974,0112};

html.append("<table border=1 valign=\"center\" width=270 height=30 
background=\"L2UI_CT1.Windows_DF_Drawer_Bg\">");
html.append("<tr>");

for(int i:arr){ 
    html.append("<td width=30><img src=\"icon.customtex_" + i + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>Name 1</td>");
}

html.append("</tr>");
html.append("</table>");

我需要更改“名称 1”等效 INT 结果

例如:

String[] arr2 = new String[] {"Name 1","Name 2","Name 3","Name 4","Name 5"};

【问题讨论】:

  • 'equivalent int 结果是什么意思?意味着数组中的相同索引?
  • 当您编写带有前导 0(如 0974)的 int 文字时,Java 将其视为八进制。 9 不是八进制的有效数字。所以我只能假设你的数组应该是int[] arr = { 254, 156, 641, 974, 112 }; - 如果这不是问题,请进一步详细说明。另外,您是否考虑过使用更现代的表生成机制?这看起来很旧的html。并且难以维护 Java。
  • @ElliottFrisch 我在一个大型项目中工作,许多文件使用 java 1.7,更新工作和学习新一代机制需要我很多时间,但我没有......但将来可能会感谢

标签: java html arrays loops each


【解决方案1】:

你只需要这样做:

for(int i=0; i<arr.length; i++){ 
    html.append("<td width=30><img src=\"icon.customtex_" + arr[i] + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>" + arr2[i] + "</td>");
}

【讨论】:

    猜你喜欢
    • 2014-06-05
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多