Zwracanie tablicy jako wyniku metody

0

witam,
chyba brakuje return w tym kodzie, tylko ze nie wiem gdzie to wstawic. Dzieki za pomoc.

import java.util.Scanner;

public class test5
{

	public static void main(String[] args)
	{
        int select = 0;
		Scanner myInput = new Scanner(System.in);

		// read in how many students to process
		System.out.println("Please enter the number of students:");
		int a = myInput.nextInt();
        String student[] = new String[a];
		double grade[] = new double[a];


			// read in student data from Scanner
			System.out.println("Please enter students name:");
		    for (int i = 0; i < student.length; i++)
		{
			student[i] = myInput.next();
		}

			System.out.println("What is the students grade?");
            for (int j = 0; j < grade.length; j++)
        {
       		System.out.println(student[j]);
			grade[j] = myInput.nextDouble();
		}


	     // show menu with options
         // Repeatedly process menu selections by the user.
			System.out.println();
			System.out.println("*** Student Exam Results Menu ***");
			System.out.println("(1) Display the average result"+"   "+"Press1");
			System.out.println("(2) Display the lowest grade"+"    "+"Pre");
			System.out.println("(3) Display the highest grade"+"  "+"P");
			System.out.println("(4) Search for specific result"+""+"L");
			System.out.println("(5) Search for student grade by name"+""+"P");
			System.out.println("(6) Exit");


do
      {

			select = myInput.nextInt();
			while ((select < 1) && (select >6));
			switch(select)
			{
			    case 1: average (grade);

			    break;
                case 2: lowest (grade);
                break;
                case 3: highest (grade);
                break;
			    case 4: sort (grade);
                break;
                case 5:
                break;
			    default: System.out.println("Thank you, Bye" );
}
}

			// get Average grade
			 public static void average (double grade[])
				   {
					 double total = 0;
					 double average = 0;
					 for (int i = 0; i < grade.length; i++)
	               {
					 total += grade[i];
					 averge = total/grade.length;
				   }
			         System.out.println("The average grade is: " + average);
			       }

			// get Lowest Grade

				   public static void lowest(double grade[])
				   {
				   	double min = grade[0];
				   	for (int i = 0; i < grade.length; i++)
				   {
					if(grade[i] < min)
				    min = grade[0];

			       }
			       System.out.println("The lowest grade is: " + low);
}
			   // get Highest Grade

				  public static void highest (double grade[])
				  {
				   double high = grade[0];
				   for (int i= 0; i < grade.length; i++)
				  {
				   if(grade[i] > high)
				   high = grade[i];
				  }
			       System.out.println("The highest grade is: " + high);
			      }
				// get Sort Grade

				    public static void sort (double grade[])
					{
					 double hold;
					 for (int pass = 1; pass < grade.length; pass++)
					 if(grade[i] > highest [i+1])
					{
					 hold = grade[i];
					 grade[i] = grade [i+1];
					 grade[i+1] = hold;
}
}
}
}
 
0

Metody, które stworzyłeś mają typ void, czyli nic nie zwracają.

0

Te Twoje sysout powinny byc zastapione np.:
return average;

sprobuj public static double[] sort(double[] array)

0

Przeczytaj jakiś podręcznik dla początkujących, dowiedz się jak wyglądają pętle while i do while oraz o konieczności deklarowania zmiennych przed ich użyciem. Jak już to opanujesz, to możesz się wziąć za zamianę metod typu void na metody typu double lub double[].

1 użytkowników online, w tym zalogowanych: 0, gości: 1