The result of this below only print out

John 90
Shawn 100
Melalin 75
Jane 80

What i want is

Melalin 75
Jane 80
John 90
Shawn 100

I tried all methods but still can't think of how to make it arrange from the lowest score to the highest. Can anyone help me? I am new to java. Thanks.

class students
{
public static void main(String args[]) 
    {
    String studentName[] = { "John ", "Shawn ", "Melalin ", "Jane " };
    double studentScore[] = { 90, 100, 75, 80 };
    int i;

    for(i=0; i<4; i++)
        {

        System.out.println(studentName [i] + studentScore [i]);
        }
    }
}

Thanks.

Well, of course it does, when you are not making any effort to sort the information. First you need to equate the data in the two arrays with each other (probably hashmap) then look at java.util.Arrays to sort the score and output the info from the hashmap.

Member Avatar for iamthwee

Were you told to implement any class infrastructure? Cos if not that's real simple.

Were you told to implement any class infrastructure? Cos if not that's real simple.

no class, just real simple coding... im a newbie in java. SO how can i do it? Can someone code it out for me? Erm, not the easy way round... not by changing the number in ascending order...

Member Avatar for iamthwee

no class, just real simple coding... im a newbie in java. SO how can i do it? Can someone code it out for me? Erm, not the easy way round... not by changing the number in ascending order...

Sorrie, we don't do people's homework. Try masijade's suggestion actually.

Or this one... http://www.jfind.com/articles/glass040700.shtml if you wanna go down the class route.

Oh thanks a lot, i have understood.

/*SORTING OF ARRAY*/
import java.util.*;

class Students
{
	public static void main(String args[])
	{
	String studentName[] = { "John ", "Shawn ", "Melalin ", "Jane " };
	double studentScore[] = { 90, 100, 75, 80 };
	//int i;
	Arrays.sort(studentName);
	for(int i=0; i<4; i++)
	{
		//Arrays.sort(studentScore);
		System.out.println(studentName [i] + studentScore [i]);
	}

	}
}

you have to just import a class named java.util.* as import java.util.* at the very beginning of your program & just write Arrays.sort(studentScore) after the definition of array.
Infact You can also sort the array according to their names.

@Casinoua: don't just hand out custom made code, certainly not if it contains logical errors.
the OP doesn't want to sort on the names, just on the codes. if you sort like you do, your names will be placed next to the wrong name.

@ stultuske

:-) why did you hitJack too old threads, zoombie :-)

If you check the posting dates you'll see that it was @casinoua who disinterred this corpse. @stultuske was just telling him off (quite rightly).

Killing this zombie now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.