【问题标题】:How can i fill one cell of array in java (android Studio)我如何在java(android Studio)中填充一个数组单元格
【发布时间】:2020-07-14 04:04:19
【问题描述】:

我写了这个,但是所有单元格都填在一起。

我该如何解决。

 Integer [] history=new Integer[5];

 for (int i=0;i<history.length;i++) {
     history[i]=Jamkon.intValue();
 }

 txt_H.setText(Arrays.toString(history));

【问题讨论】:

  • 写完txt_H.setText(Arrays.toString(history));之后,输出是什么,你想得到什么作为正确的输出?
  • 看看这个:array fill method

标签: java android arrays for-loop debugging


【解决方案1】:

您正在使用一个循环,它将遍历数组的所有索引。如果您只想写入一个值,则必须首先决定 index 是什么。

    int index =??? 
    history[index] = Jamkon.intValue()

【讨论】:

  • 我想在下次单击按钮时打印第一个单元格打印最后一个单元格和下一个单元格,直到所有单元格都填满。
  • 您需要将该索引保存在某处,并在用户每次点击时对其进行读/写。请显示更多您的代码。
  • 我修好了 tnx 先生。
  • 请检查我的答案以解决问题,或者更确切地说,发布您自己的解决方案作为正确答案供其他人查看!
猜你喜欢
  • 1970-01-01
  • 2010-11-12
  • 2014-09-15
  • 1970-01-01
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多