title: Sorting a string array and a int array
body: <p>I am practicing sorting of arrays, and I have successfully sorted a string array.</p>
  
  <p>My little program allows users to enter first number of students, then the name of each one, and at last their grade of each one.</p>
  
  <p>But I also want to sort the int <code>studentGrade</code> array so that the grades in the printout matches the student. Here I am really stuck. See further down for more explanation down in the method:  <code>public void sortingAlgorithm</code></p>
  
  <pre><code>package assignment8exam;
  
  import java.util.Scanner;
  import java.util.Arrays;
  
  /**
   *
   * @author Anders
   */
  public class Course {
  
      Scanner sc = new Scanner(System.in);
  
      public void MainMenu() {
  
          System.out.println("Enter data about a student, start by entering how many");
  
          int numbers = sc.nextInt();// amount of student
          String studentNames[] = new String[numbers];
          int studentGrade[] = new int[numbers];
          for (int i = 0; i &lt; numbers; i++) {
  
              System.out.println("Enter name of student");
              Scanner name = new Scanner(System.in);
  
              String names = name.nextLine();
              studentNames[i] = names;
          }
  
          for (int j = 0; j &lt; numbers; j++) {
  
              System.out.println("Enter grade of student");
              Scanner gradeSc = new Scanner(System.in);
  
              int grade = gradeSc.nextInt();
              studentGrade[j] = grade;
          }
  
          sortingArray(studentNames);
          System.out.println("------------------------------------\n");
          sortAlgorithm(studentNames, studentGrade);
          System.out.println("What do you want");
          System.out.println("Exit application 1");
          System.out.println("Print out all names of the students 2");
          System.out.println("Print out all the grades of the students 3");
          System.out.println("Print out pairs consisting of “name­grade 4");
          System.out.println("Search for a student - 5");
          Scanner choice = new Scanner(System.in);
          int order = choice.nextInt();
  
          switch (order) {
  
              case 1:
                  System.exit(1);
  
              case 2:
                  PrintOutNames(numbers, studentNames);
  
              case 3:
                  PrintOutGrades(numbers, studentGrade);
  
              case 4:
                  PrintOutAll(numbers, studentGrade, studentNames);
  
              case 5:
                  search(numbers, studentGrade, studentNames);
  
          }
  
      }
  
      public static void PrintOutNames(int numbers, String studentNames[]) {
  
          for (int i = 0; i &lt; numbers; i++) {
  
              System.out.println(studentNames[i]);
  
          }
      }
  
      public static void PrintOutGrades(int numbers, int studentGrade[]) {
  
          for (int i = 0; i &lt; numbers; i++) {
  
              System.out.println(studentGrade[i]);
  
          }
  
      }
  
      public static void PrintOutAll(int numbers, int studentGrade[], String studentNames[]) {
          System.out.println("--------------------------------------------------------\n");
          for (int i = 0; i &lt; numbers; i++) {
  
              System.out.println("Name----&gt; " + studentNames[i] + " grade ---&gt; " + studentGrade[i]);
  
          }
  
      }
  
      public static void search(int numbers, int studentGrade[], String studentNames[]) {
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter name on student you want to search on ");
          String search = sc.nextLine();
          for (int i = 0; i &lt; numbers; i++) {
  
              if (search.equals(studentNames[i])) {
  
                  System.out.println("Yes we have a student named " + studentNames[i] + " with the Grade " + studentGrade[i] + " \n ");
  
              }
  
          }
      }
  
      public static void sortingArray(String studentNames[]) {
  
          Arrays.sort(studentNames);
          System.out.println("-------------\n" + Arrays.toString(studentNames));
  
      }
  
      public static void sortAlgorithm(String studentNames[], int studentGrade[]) {
  
          boolean flag = true;
  
          while (flag) {
  
              flag = false;
  
              for (int j = 0; j &lt; studentNames.length - 1; j++) {
  
                  for (int i = j + 1; i &lt; studentNames.length; i++) {
                      if (studentNames[i].compareTo(studentNames[j]) &lt; 0) {
                          String temp = studentNames[j];
                          studentNames[j] = studentNames[i];
                          studentNames[i] = temp;
  
                                                                                               // Here i want to place another array that sorts the grade?? how do i do that?
                      }
  
                  }
  
                  System.out.println(Arrays.toString(studentNames));
                  System.out.println(Arrays.toString(studentGrade));
  
              }
          }
      }
  }
  </code></pre>