Борьба с массивами в Java - PullRequest
0 голосов
/ 24 мая 2018

Это изображение требований, которым я должен следовать и которые включают

У меня проблемы со всем, что не очень хорошо с массивами.Это то, что я до сих пор Любая помощь будет оценена.Спасибо Часть, над которой я больше всего борюсь, это шаг 2. Что касается шагов 3 и 4, у меня есть часть требования, мне просто нужно вернуть имя и идентификационный номер, а также набрать наивысший и наименьший балл.

    import java.util.*;

    public class Final project

    {
      public static void main(String args[])
      {

     Scanner console = new Scanner(System.in);

    int[] studentID = new int [5];

    String[] studentName = new String [5];

    int [] studentScore = new int [5];

    for (int i = 0; i < 5; i++)

     { 

      System.out.println("Student Number " + (i+1) + "");

    System.out.println("Student ID Number: ");

    studentID [i] = console.nextInt();

    System.out.println(" Student Name: " + console.nextLine()+"");

     studentName [i] = console.nextLine();

     System.out.println("Grade: ");

      studentScore [i] = console.nextInt();

     }

    int max = printLowest(studentScore);

    System.out.println("Highest score is: "+max);

    int min = printHighest(studentScore);

     System.out.println("Lowest score is: "+min);

    }


     public static int printLowest(int[] inputArray){ 

     int maxValue = inputArray[0]; 

     for(int i=1;i < inputArray.length;i++){ 

     if(inputArray[i] > maxValue){ 

      maxValue = inputArray[i]; 

      } 

     } 

     return maxValue; 

    }

     public static int printHighest(int[] inputArray){ 

    int minValue = inputArray[0]; 

     for(int i=1;i<inputArray.length;i++){ 

     if(inputArray[i] < minValue){ 

      minValue = inputArray[i]; 

     } 

      } 

      return minValue; 

    } 

    }

1 Ответ

0 голосов
/ 24 мая 2018
You can try something like this:
public static void printRoster()
{
  for (int i = 0; i < 5; i++)

     { 
java.util.Arrays.sort(studentid);
java.util.Arrays.sort(studentName );
java.util.Arrays.sort(studentScore);
 }
for(int i=0;i<5;i++)
{
 System.out.println(studentid[i] + " " + studentName [i] + " " + studentScore 
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...