View Single Post
  #1 (permalink)  
Old 12-17-2007, 09:11 AM
lowpro lowpro is offline
Member
 
Join Date: Nov 2007
Location: boston
Posts: 10
lowpro is on a distinguished road
need help with bubble sort
// hello everyone my code is not doing the sort please help big thnks adv
import java.util.Scanner;

public class C6E19{
public static void main(String [] args){
int numberOfStudents;
Scanner input = new Scanner(System.in);

System.out.println(" please enter # of student");
numberOfStudents = input.nextInt();

String[] studentNames = new String[numberOfStudents];

int[] studentScores = new int[numberOfStudents];

for(int i = 0; i < numberOfStudents; ++i)
{
System.out.println("enter student name");
studentNames[i] = input.next();
System.out.println("enter student score");
studentScores[i] = input.nextInt();

} /// print arrray////
printArray(studentNames, studentScores, numberOfStudents);


}//end main
/////call array///
public static void printArray(String[] namesPassed, int[] scoresPassed,
int numberOfStudentsPassed)
{
for(int i = 0 ; i < numberOfStudentsPassed; ++i){
System.out.println(namesPassed[i] + " " + scoresPassed[i]);
}// end for

} //end method printArray

/////////sort///////////
public static void bubbleSortInt(int[] scoresPassed)
{

boolean changed = true;
do{
changed = false;

for(int i = 0; i < scoresPassed.length - 1; ++i)
{
if(scoresPassed[i] < scoresPassed[i + 1])
{
int tempScore = scoresPassed[i];
scoresPassed[i] = scoresPassed[i + 1];
scoresPassed[i + 1] = tempScore;
changed = true;
}// end if
}

}while (changed);

} // bubblesort

}//end class
Reply With Quote
Sponsored Links