Ask Question

c Write a program that, given a series of integer numbers, identifies the two largest numbers in the list. The user will specify at the beginning how many numbers will be in the list; you may assume that there will always be at least two numbers entered.

+5
Answers (1)
  1. 3 August, 03:35
    0
    import java. util. Arrays;

    import java. util. Scanner;

    import java. util. Collections;

    public class num1 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("How many numbers: ");

    int num = in. nextInt ();

    int [] numArray = new int[num];

    for (int i = 0; i
    System. out. println ("Enter the numbers: ");

    numArray[i] = in. nextInt ();

    }

    //Print the list of numbers entered

    System. out. println ("You entered these numbers " + Arrays. toString (numArray));

    //finding the minimum

    int min = numArray[0];

    for (int i = 0; i
    if (numArray[i]
    min = numArray[i];

    }

    }

    System. out. println ("The minimum is "+min);

    int max = numArray[0];

    for (int i = 0; i
    if (numArray[i]>max) {

    max = numArray[i];

    }

    }

    System. out. println ("The maximum is "+max);

    }

    }

    Explanation:

    In the program above;

    The user will be prompted to enter the length of the list (n) with the assumption that it will always be more than two

    An array is created of the size (n)

    User is prompted to enter the numbers in the list

    Using a combination of for loops and if statements, the max and min is outputed
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “c Write a program that, given a series of integer numbers, identifies the two largest numbers in the list. The user will specify at the ...” 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