0

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;

2 Answers 2

2

I don't understand where you're setting i. Don't you simply want:

 list[k]++;

to incremement the decile found at index k ?

Sign up to request clarification or add additional context in comments.

1 Comment

I had it has list[k]=++; I cannot believe I just spent an hour trying to fix that. Thanks Brian!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.