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

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

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

问题

  1. i have this code:
  2. int[] arr = new int[] {0254,0156,0641,0974,0112};
  3. html.append("<table border=1 valign=\"center\" width=270 height=30
  4. background=\"L2UI_CT1.Windows_DF_Drawer_Bg\">");
  5. html.append("<tr>");
  6. for(int i:arr){
  7. html.append("<td width=30><img src=\"icon.customtex_" + i + "\" width=32 height=32></td>");
  8. html.append("<td align=\"center\" width=290>" + arr2[i] + "</td>");
  9. }
  10. html.append("</tr>");
  11. html.append("</table>");
  12. i need change "Name 1" equivalent INT result
  13. for example:
  14. String[] arr2 = new String[] {"Name 1","Name 2","Name 3","Name 4","Name 5"};
英文:

i have this code:

  1. int[] arr = new int[] {0254,0156,0641,0974,0112};
  2. html.append(&quot;&lt;table border=1 valign=\&quot;center\&quot; width=270 height=30
  3. background=\&quot;L2UI_CT1.Windows_DF_Drawer_Bg\&quot;&gt;&quot;);
  4. html.append(&quot;&lt;tr&gt;&quot;);
  5. for(int i:arr){
  6. 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;);
  7. html.append(&quot;&lt;td align=\&quot;center\&quot; width=290&gt;Name 1&lt;/td&gt;&quot;);
  8. }
  9. html.append(&quot;&lt;/tr&gt;&quot;);
  10. html.append(&quot;&lt;/table&gt;&quot;);

i need change "Name 1" equivalent INT result

for example:

  1. 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

你只需要这样做:

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

You just need to do this:

  1. for(int i=0; i&lt;arr.length; i++){
  2. 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;);
  3. html.append(&quot;&lt;td align=\&quot;center\&quot; width=290&gt;&quot; + arr2[i] + &quot;&lt;/td&gt;&quot;);
  4. }

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:

确定