I have a confusion of how to put that max and min in main method so it would run.
PS: there might be mistakes
The goal is to create a method that enter any numbers by user and it suppose to show the Max and Min.
PLEASE HELP~! what is wrong with this?
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("How many numbers will be entered?");
int num = scanner.nextInt();
double[] grades = new double[num];
for(int i = 0; i < grades.length; i++)
{
System.out.println("Enter an integer: ");
grades[i] = scanner.nextDouble();
}
}
public static int max(int[] numbers)
{
int max = numbers[0];
for(int i = 0; i < numbers.length; i++)
{
if(numbers[i] > max)
max = numbers[i];
System.out.println("Maximum = " + max);
}
return max;
}
public static int min(int[] numbers)
{
int min = numbers[0];
for(int i = 0; i < numbers.length; i++)
{
if(numbers[i] < min)
min = numbers[i];
System.out.println("Minimum = " + min);
}
return min;
}