如何在Java中为字符串和整数添加循环。

huangapple go评论76阅读模式
英文:

how to add in a loop for string and int in java

问题

i have this code:

    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>" + arr2[i] + "</td>");
    }
    
    html.append("</tr>");
    html.append("</table>");

i need change "Name 1" equivalent INT result

for example:

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

i have this code:

int[] arr = new int[] {0254,0156,0641,0974,0112};
	
html.append(&quot;&lt;table border=1 valign=\&quot;center\&quot; width=270 height=30 
background=\&quot;L2UI_CT1.Windows_DF_Drawer_Bg\&quot;&gt;&quot;);
html.append(&quot;&lt;tr&gt;&quot;);

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

html.append(&quot;&lt;/tr&gt;&quot;);
html.append(&quot;&lt;/table&gt;&quot;);

i need change "Name 1" equivalent INT result

for example:

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

答案1

得分: 0

你只需要这样做:

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>");
}
英文:

You just need to do this:

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

huangapple
  • 本文由 发表于 2020年5月5日 08:30:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/61603863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定