View Single Post
  #8 (permalink)  
Old 05-13-2008, 08:47 PM
masaka masaka is offline
Member
 
Join Date: Mar 2008
Posts: 31
masaka is on a distinguished road
now this the final code i want
import java.util.*;
public class Main {
static Scanner console= new Scanner(System.in);
public static void main(String[] args)
{
String []names=new String[2];
for(int i =0;i<names.length;i++)
{
System.out.print("Please Enter Student name ");
System.out.println();
names[i] =console.next();
}
int []grade=new int[2];
for(int i =0;i<grade.length;i++)
{
System.out.print("Please Enter Student grade ");
System.out.println();
grade[i] =console.nextInt();
}
sortname(names,grade);
// here should be acall to amethod to prtint the arrays after sorting
// i donnot know how to return the sorted arrays to make the print
}
public static void sortname(String[] names, int[] grade){
boolean swapped;
do{
swapped = false;
for (int i = 0; i < names.length-1; i++)
{
if(names[i].compareToIgnoreCase(names[i+1])>0)
{
String temp = names[i+1];
names[i+1] = names[i];
names[i] = temp;
// here after sort the name we make acall to the second mehthod
sortgrade(names,grade,i);
swapped=true;
}
}
}while(swapped);

}
public static void sortgrade(String []names,int[] grade ,int i)
{ // this method to sort the garde arry
if(names[i].compareToIgnoreCase(names[i+1])>0)
{
int temp1 = grade[i+1];
grade[i+1] = grade[i];
grade[i] = temp1;
}

}
// here will be the print method
}
Reply With Quote