201k views
1 vote
Write a main program that prompts users for 5 integers. Use two separate functions to return (NOT print) the highest and lowest value of the 5 integers. From main, display all five numbers entered and the results.

User Siega
by
6.3k points

1 Answer

4 votes

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class LatinHire {

public static void main(String[] args) {

Scanner in = new Scanner (System.in);

System.out.println("Enter Five integers");

int num1 = in.nextInt();

int num2 = in.nextInt();

int num3 = in.nextInt();

int num4 = in.nextInt();

int num5 = in.nextInt();

int [] intArray = {num1,num2,num3,num4,num5};

System.out.println(Arrays.toString(intArray));

System.out.println("The Maximum is "+returnMax(intArray));

System.out.println("The Minimum is "+returnMin(intArray));

}

public static int returnMax(int []array){

int max = array[0];

for(int i=0; i<array.length; i++){

if(max<array[i]){

max= array[i];

}

}

return max;

}

public static int returnMin(int []array){

int min = array[0];

for(int i=0; i<array.length; i++){

if(min>array[i]){

min= array[i];

}

}

return min;

}

}

Step-by-step explanation:

  1. This is implemented in Java Programming Language
  2. Two Methods are created returnMax(Returns the Maximum Value of the five numbers) and returnMin(Returns the minimum of the five numbers)
  3. In the Main method, the user is prompted to enter five numbers
  4. The five numbers are saved into an array of integers
  5. The returnMax and returnMin methods are called and passed the array as parameter.
  6. The entire array of numbers inputted by the user as well the Max and Min are printed

User LionisIAm
by
6.4k points