Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with 5 method java program. Thanks Develop a method called max that

ID: 3815499 • Letter: P

Question

Please help with 5 method java program. Thanks

Develop a method called max that takes a parameter of an integer array and

returns the largest value stored in the parameter.

Develop a method called min that takes a parameter of an integer array and returns the smallest value stored in the parameter.

Develop a method called maxMin that takes a parameter of an integer array and returns both the largest value and the smallest value in the parameter in an array of length two.

Test your methods in a program and include a method that reads a list, terminated by -999, into an array.

In total, your program will contain 5 methods, max, min, maxMin, the method that reads input, and main.

Explanation / Answer

MethodsTest.java

package a6;

import java.util.ArrayList;
import java.util.Scanner;

public class MethodsTest {

  
   public static void main(String[] args) {
   int a[] = readArray();
   int values[] = maxMin(a);
   System.out.println("Max value is "+values[0]);
   System.out.println("Min value is "+values[1]);
   }
   public static int[] readArray() {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the list of integers: ");
       int n = scan.nextInt();
       ArrayList<Integer> list = new ArrayList<Integer>();
       while( n != -999){
           list.add(n);
           n = scan.nextInt();
       }
       int a[] = new int[list.size()];
       for(int i=0; i<list.size(); i++){
           a[i]=list.get(i);
       }
       return a;
   }
   public static int max (int array[]){
       int maxValue = array[0];
       for(int i=0; i<array.length; i++){
           if(maxValue<array[i]){
               maxValue = array[i];
           }
       }
       return maxValue;
   }
   public static int min (int array[]){
       int minValue = array[0];
       for(int i=0; i<array.length; i++){
           if(minValue>array[i]){
               minValue = array[i];
           }
       }
       return minValue;
   }
   public static int[] maxMin (int array[]){
       int values[] = new int[2];
       values[0]=max(array);
       values[1]=min(array);
       return values;
   }
}

Output:

Enter the list of integers:
4 5 1 2 3 8 10 6 9 -999
Max value is 10
Min value is 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote