1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MakcuM [25]
3 years ago
8

Declare an array to hold eight integers. Use a for loop to add eight random integers, all in the range from 50 to 100, inclusive

, to this array. Duplicates are okay. Next, pass the array to a method that sorts the array and returns another array containing only the largest and smallest elements in the original array. Print these two values in main. Then use a foreach loop to display all elements of the sorted array on one line separated by a single space. This latter loop should also count the odd and even numbers in the array and determine the sum of all elements in the array. SAMPLE OUTPUT The lowest element is 59 The highest element is 96 Here is the array 59 64 76 77 80 88 91 96 Evens: 5, odds: 3 Total: 631
my code:

I am stuck on the problem to return the highest value and lowest value. Also on sorting the randomly generated integers. All in Java programming.

private static Random rand = new Random();

public static void main(String[] args){
int[] randomEight = numbers();
// printArray(randomEight);
System.out.println("The lowest element is");
System.out.println("The highest element is");
System.out.println("Here is the array");
// System.out.println(Arrays.toString(randomEight));
System.out.println();
for(int i = 0; i System.out.println(randomEight[i] + " ");
}
}
}
Computers and Technology
1 answer:
makvit [3.9K]3 years ago
5 0

Answer:

Explanation:

import java.util.Random;

public class RandomGen {

  private static Random rand = new Random();

  public static void main(String args[]) {

      int[] randomEight = new int[8];

      for(int i=0; i<8; i++) {

          /*

          * Get a random number between 50 and 100

          * */

          randomEight[i] = rand.nextInt(51) + 50;

      }

     

      int[] extremeValues = sortArray(randomEight);

      System.out.println("The lowest element is " + extremeValues[0]);

      System.out.println("The highest element is " + extremeValues[1]);

     

      int sum = 0;

      int oddCount = 0;

      int evenCount = 0;

     

      System.out.println("\nThe contents of the sorted array are : ");

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

          System.out.print(randomEight[i] + " ");

          if (randomEight[i]%2==0) {

              evenCount++;

          }

          else {

              oddCount++;

          }

          sum += randomEight[i];

      }

      System.out.println("\nEven numbers count : " + evenCount);

      System.out.println("\nOdd numbers count   : " + oddCount);

      System.out.println("\nSum of all elements : " + sum);      

     

  }

  public static int[] sortArray(int[] input) {

      int extremeVal[] = new int[2];

      extremeVal[0] = input[0];   /* Minimum */

      extremeVal[1] = input[1];   /* Maximum */

      /*

      * Bubble Sort Algorithm

      * */

      int n = input.length;

      for (int i=0; i<n-1; i++) {

          for (int j=0; j<n-i-1; j++) {

              if (input[j] > input[j+1]) {

                  int temp = input[j];

                  input[j] = input[j+1];

                  input[j+1] = temp;

              }

          }

         

          /* Finding minimum */

          if (extremeVal[0] > input[i]) {

              extremeVal[0] = input[i];

          }

          /* Finding maximum */

          if (extremeVal[1] < input[i]) {

              extremeVal[1] = input[i];

          }

         

      }

      return extremeVal;

  }

}

 The lowest element is 58

The highest element is 71

The content of the sorted array are:

51 52 58 59 59 63 71 100

Even numbers count  :3

Odd numbers count   :5

Sum of all element      :513

You might be interested in
Why should we be concerned about HVAC systems when discussing security?
lana66690 [7]

Answer:

 HVAC is stand for the heating, ventilation and the air conditioning system that basically perform various type computer management and operation system. It also helps to improve the productivity of the system.

 As, HVAC system is very concerned about the security as it basically include various types of toxic chemical in the environment that include various types of criminal and terrorist activities and natural disaster.

The HVAC systems are easily cause various accidental cases due to its complexity nature. It also performing various types of function in the management sector like maintenance, system updating function an remote controlling maintenance.

4 0
4 years ago
Describe the objectives of e-commerce ?​
AnnZ [28]

Answer: eCommerce is to reach the more and right customers at the right time so that more orders can be placed and in turns, high revenue can be generated.

Explanation:

5 0
3 years ago
The method of making paper is called p.........
Scorpion4ik [409]

ANSWER:

the answer is pulping

The method of making paper is called pulping

~batmans wife dun dun dun...aka ~serenitybella

4 0
3 years ago
Read 2 more answers
Applying Time Management Techniques
tatuchka [14]

Answer:

Most students start out each new semester of school with high expectations. They envision themselves being successful in their studies and school work but they fail to put together a realistic plan, or establish a routine, that will enable them to achieve academic success. There are only so many hours in a day, days in a week, and weeks in a term. And if you don't pay attention, the end of the semester will arrive before you know it – catching you by surprise. To achieve academic success, you must carefully manage your study time on a daily, weekly, and semester basis. The following is a time management strategy for doing exactly that.

Explanation:

7 0
4 years ago
alex needs to email his graduation certificate to a prospective employer. he has only physical copies of the certificate. what d
svlad2 [7]
He should use a scanner, which would convert an image into an electronic file.
7 0
3 years ago
Other questions:
  • Consider a file system that uses inodes to represent files. Disk blocks are 2KB in size and a pointer to a disk block requires 4
    13·1 answer
  • Sam's manager would like him to create and distribute copies of a budget report for each department. The budget report should sh
    8·2 answers
  • All spreadsheet formula should start with
    12·1 answer
  • Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T
    9·1 answer
  • This common technique, employed at the edge of a network, eliminates the need for public IP addresses on a private network while
    8·1 answer
  • Which of the following are agricultural industry clusters? Human population systems, computer technoloy biotechnology or food pr
    9·1 answer
  • 5 of 10
    7·1 answer
  • Credible sites contain __________ information,
    7·2 answers
  • The Operating System provides utility software designed to perform specific tasks. What task(s) does it perform? Select all that
    11·1 answer
  • 8.7 Code Practice Question 3
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!