#How to return 1 value from an array?

1 messages · Page 1 of 1 (latest)

safe crow
#
import java.util.Scanner;

/*
 * Create a program which displays the following menu options available to the user: 
 * 1...students marks are entered, 
 * 2...view thehighest mark entered so far,
 * 3...display the lowest mark entered so far
 * 4...display average
 * 5...Exit
 */

public class Topic5_5num7
{

    static Scanner sc = new Scanner(System.in);
    static int[] arrayReturned = null;


    public static void main(String[]args) 
    {
        System.out.println("1...Students marks are entered");
        System.out.println("2...View the highest mark entered so far");
        System.out.println("3...Display the lowest mark entered so far");
        System.out.println("4...Display average");
        System.out.println("5...Exit");

        System.out.println("");

        System.out.print("Enter your choice: ");
        int choice = sc.nextInt();
        while(choice!=5)
        {
            if (choice==1)
            {
                arrayReturned = marks();
            }
            else if (choice==2)
            {
                int highestMarkReturned = highestMark(arrayReturned);
            }
            else if (choice==3)
            {

            }
            else if (choice==4)
            {

            }
            System.out.print("Enter your choice: ");
            choice = sc.nextInt();
        }
    }

    public static int[] marks()
    {
        System.out.print("Enter how many marks you would like to enter: ");
        int num = sc.nextInt();

        int[] array = new int[num];
        for(int i = 0; i>array.length; i++)
        {
            System.out.print("Enter mark "+(i+1)+ ":");
            array[i] = sc.nextInt();
        }
        
        return array;
    }
    
    public static int highestMark(int arrayReturnedIn)
    {
        
    }
}
tribal wraithBOT
#

<@&987246399047479336> please have a look, thanks.

tribal wraithBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.