Community discussion forum

How to sorts the names in alphabetical order in an array

Tags: java Egypt
  • 6 months 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).