Reputation: 11
So I have set up an array 'generateUser' in a method called by my main. However, when i run it, it replaces the value the index with a cumulative i value. instead of every time the dectile 7, for example, comes up it just replaces index 7 with the current value of i. i see what is wrong, but I don't know how to fix it. I think the problem line is
list[k]=++i;//HELP
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;
Upvotes: 0
Views: 2987
Reputation: 2490
I thing you want something like that:
list[counter]=k;
because u want a to fill a list with 10 users at the end?
with list[k]=++i;
you don't set your index. You set the Value at position k in the array list.
Upvotes: 0
Reputation: 272427
I don't understand where you're setting i
. Don't you simply want:
list[k]++;
to incremement the decile found at index k
?
Upvotes: 2