Results 1 to 6 of 6
- 06-12-2011, 08:42 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
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]);
- 06-12-2011, 09:34 PM #2
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.
Are the arrays in parallel? The data for each student is at the same index in each array.cant link it to the student array to get the student name
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.
- 06-12-2011, 09:52 PM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Minimum average? what is that, and how is it calculated?
- 06-12-2011, 10:03 PM #4
Member
- Join Date
- Jun 2011
- Posts
- 12
- Rep Power
- 0
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
- 06-12-2011, 10:10 PM #5
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]
- 06-14-2011, 01:28 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Similar Threads
-
How to persist multidimensional Java arrays using JPA
By T_O_B_E_E in forum JDBCReplies: 0Last Post: 02-14-2011, 03:24 PM -
Multidimensional Arrays
By holytanx in forum New To JavaReplies: 1Last Post: 08-05-2010, 10:28 PM -
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03-23-2010, 01:40 AM -
Make Java codes more simplier (Multidimensional Arrays)
By javanewbie in forum JCreatorReplies: 9Last Post: 06-25-2008, 04:48 AM -
Multidimensional arrays
By Java Tip in forum Java TipReplies: 0Last Post: 11-05-2007, 05:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks