How to sorts the names in alphabetical order in an array

java Egypt
  • 12 years ago

    Hi, i have 2 arrays the frist is to stroe students names and the second is for students grades i want to sort the names in alphabetical order and the grades moves to its names how to do this

    import java.util.*;
    public class Main {
    static Scanner console= new Scanner(System.in);
        public static void main(String[] args)
        {
       String []names=new String[10];   
       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[10];   
       for(int i =0;i<grade.length;i++)
       {
        System.out.print("Please Enter Student name ");
        System.out.println();
        grade[i] =console.nextInt();
        }
        
      }
    // Now I want to define a method that sort the names
    // and then moves the grade to its name   
    }

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor