www.webdeveloper.com
Results 1 to 3 of 3

Thread: a little help please

  1. #1
    Join Date
    Jun 2010
    Posts
    3

    a little help please

    I'm new to java, never programmed before, and I'm having some trouble with this code. It tells me that it requires a int[] value, but is getting a int value. I'm not too sure how to fix this.

    Thank you in advance for any help you can provide.

    Here is the section of code:

    public static int[] createBucketCounts(double [] data, int n) {
    double min = DescriptiveStatistics.getMinimum(data);
    double max = DescriptiveStatistics.getMaximum(data);
    double range = max - min;
    double width = range / 10;

    int[] bucketCounts ={
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    for (int i = 0; i < data.length; i++){
    if (data[i] <= min + width){
    return bucketCounts[0] += 1;
    }
    else if (data[i] <= min + (width * 2)){
    return bucketCounts[1] += 1;
    }
    else if (data[i] <= min + (width * 3)){
    return bucketCounts[2] += 1;
    }
    else if (data[i] <= min + (width * 4)){
    return bucketCounts[3] += 1;
    }
    else if (data[i] <= min + (width * 5)){
    return bucketCounts[4] += 1;
    }
    else if (data[i] <= min + (width * 6)){
    return bucketCounts[5] += 1;
    }
    else if (data[i] <= min + (width * 7)){
    return bucketCounts[6] += 1;
    }
    else if (data[i] <= min + (width * 8)){
    return bucketCounts[7] += 1;
    }
    else if (data[i] <= min + (width * 9)){
    return bucketCounts[8] += 1;
    }
    else if (data[i] <= min + (width * 10)){
    return bucketCounts[9] += 1;
    }
    return bucketCounts;
    }

    } // end of createBucketCounts

  2. #2
    Join Date
    Jun 2010
    Posts
    3
    I am trying to take an array of numbers, divide them into ten "buckets" - ranges of numbers actually - and have each bucket keep a tally, and turn that tally into an array.

  3. #3
    Join Date
    Jun 2010
    Posts
    3
    Never mind, it was the return statements that were causing the issue.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles