所以我在我的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