Ask Question
24 August, 19:38

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. 24 August, 20:01
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers