Results 1 to 6 of 6
  1. #1
    belfast09 is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default arrays and multidimensional arrays

    I have set an array of 8 students and then 8 multidimensional arrays of 3 for their results i got their average but have to display which students has the minumum average score ive no problem displaying the minum average mark but cant link it to the student array to get the student name into the output with there mark here is my method i be very thankful of some help


    public void Min()
    {
    int[] max = new int[8]; // allocates memory for 8 integers
    max[0]= (marks[0][0] + marks[0][1] + marks[0][2])/3;
    max[1]= (marks[1][0] + marks[1][1] + marks[1][2])/3;
    max[2]= (marks[2][0] + marks[2][1] + marks[2][2])/3;
    max[3]= (marks[3][0] + marks[3][1] + marks[3][2])/3;
    max[4]= (marks[4][0] + marks[4][1] + marks[4][2])/3;
    max[5]= (marks[5][0] + marks[5][1] + marks[5][2])/3;
    max[6]= (marks[6][0] + marks[6][1] + marks[6][2])/3;
    max[7]= (marks[7][0] + marks[7][1] + marks[7][2])/3;

    Arrays.sort(max);
    System.out.println("The minimum score is = " + max[0]);

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Can you explain what the code you posted is supposed to do?
    How does the the printed message at the bottom relate to the code?

    Do you see the repeating pattern in the code? 0 1 2 3 ... thru 7
    When you see that you should think: loop
    Your code should have a loop instead of the 8 statements you have.

    cant link it to the student array to get the student name
    Are the arrays in parallel? The data for each student is at the same index in each array.
    How do you get the index of the score that you are displaying? The code shows a constant index of 0 and not a variable.

  3. #3
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Minimum average? what is that, and how is it calculated?

  4. #4
    belfast09 is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default

    sorry mate no how do you loop this, im using the three marks and am using an array of all the student marks and using array.sort to get the lowest average when you talk about parallel index this is my mistake could you demonstrated sorry very new to java

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Go to your text book or tutorial about programming and read about how to use a for loop.
    You can search on this forum for many examples of for loops.

    If you sort the contents of an array, then you won't be able to use parallel arrays because the sorting process will remove the correspondence between the arrays. By correspondence I mean that the data at any index in all the arrays is for the same student. The scores[ix] would be for studentName[ix]

  6. #6
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by belfast09 View Post
    sorry mate no how do you loop this, im using the three marks and am using an array of all the student marks and using array.sort to get the lowest average when you talk about parallel index this is my mistake could you demonstrated sorry very new to java
    Sorry, I don't understand what you're saying. I was asking for an explanation of what the minimum average was and the algorithm for calculating it.

Similar Threads

  1. Replies: 0
    Last Post: 02-14-2011, 03:24 PM
  2. Multidimensional Arrays
    By holytanx in forum New To Java
    Replies: 1
    Last Post: 08-05-2010, 10:28 PM
  3. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  4. Replies: 9
    Last Post: 06-25-2008, 04:48 AM
  5. Multidimensional arrays
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 05:07 PM

Posting Permissions

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