所以我在我的main调用的方法中设置了一个数组'generateUser'。但是,当我运行它时,它会使用累积的i值替换索引值。例如,而不是每次出现陡峭的7时,它都会将索引7替换为i的当前值。我发现有什么不对,但我不知道如何解决。我认为这个问题行是更改数组值java
列表[K] = ++我; //帮助
public static int [] generateUser(int n)
{
//pass number of students int n;
int [] list = new int[10];
int i=0;
int total, counter, k;
int score;
String str3;
total = counter =0;
while (total < n)
{
str3 = JOptionPane.showInputDialog("Please enter the score: (1-100) ");
score = Integer.parseInt(str3);
System.out.print(str3+"\t");
if (score <1 || score >100)
{
JOptionPane.showMessageDialog(null,"The data must be betwen 1 and 100.");
}
k = (score-1)/10;
list[k]=++i;//HELP
total = counter ++;
}
return list;
我试过了,得到一个编译器错误。 :( – MaryK 2013-03-07 09:35:59
ummm斜线我是一个白痴 – MaryK 2013-03-07 09:36:46
我有它列表[k] = ++;我不能相信我只花了一个小时试图解决这个问题,谢谢布莱恩! – MaryK 2013-03-07 09:37:26