Ask Question
21 April, 21:45

Write an algorithm to print the minimum and maximum of an integer array. Your need to pass the array as a parameter. Since we cannot return two values (in this case, minimum and maximum), just print them inside the method. You are allowed to use only one loop. i. e. you are not allowed to traverse the array twice. Note: You can write a Java method instead of pseudo-code but pseudo-code is preferred. Following is a template to start your pseudo code. MinMax (A) min

+3
Answers (1)
  1. 22 April, 01:19
    0
    See explaination

    Explanation:

    MinMax. java

    import java. util.*;

    public class MinMax

    {

    static void MinMax (int[] arr)

    {

    int Min=arr[0]; / / initializinf min and max with 1st value of array

    int Max=arr[0];

    for (int i=0; i
    {

    if (arr[i]>Max) / / checking max value

    {

    Max=arr[i];

    }

    if (arr[i]
    {

    Min=arr[i];

    }

    }

    System. out. println ("Min Number is "+Min); / /printing min value

    System. out. println ("Max Number is "+Max); / /printing max value

    }

    public static void main (String[] args) {

    Scanner sc = new Scanner (System. in);

    System. out. print ("Enter N value: "); / / taking n value

    int n=sc. nextInt ();

    int[] arr=new int[n];

    System. out. println ("Enter N elements:"); / / taking n elements into array

    for (int i=0; i
    {

    arr[i]=sc. nextInt (); / / each element into the array

    }

    MinMax (arr); / / calling MinMax () method.

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write an algorithm to print the minimum and maximum of an integer array. Your need to pass the array as a parameter. Since we cannot return ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers