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
Mandarinka [93]
3 years ago
7

Create an application containing an array that stores eight integers. The application should call five methods that in turn (1)

display all the integers, (2) display all the integers in reverse order, (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value. Save the file as ArrayMethodDemo.java.
Computers and Technology
1 answer:
Butoxors [25]3 years ago
3 0

Answer:

package b4;

public class ArrayMethodDemo {

public static void main(String[] args) {

 // Create an array to store 8 random integers.

 int[] integernumbers = { 3, 4, 6, 9, 5, 6, 7, 2 };

 // Call the display method to show the elements in the array.

 display(integernumbers);

 // Call the method to display the elements in reverse order.

 displayReverse(integernumbers);

 // Call the method to find the sum of the elements.

 sum(integernumbers);

 // Call the method to display all elements less than a limiting value, say 5.

 lessThan(integernumbers, 5);

 // Call the method to display all elements greater than the average of the array

 // elements.

 higherThan(integernumbers);

}

// Method to display the elements in the array.

// The method receives only a single argument which is the array.

// Loop through the array and at every cycle, print out each element

public static void display(int[] arr) {

 System.out.print("All integers in the array : ");

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

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

 }

 System.out.println();

}

// Method to display the elements in the array in reverse order

// The method receives only a single parameter which is the array

// Loop through the array starting at the last index

// At every cycle, print out the elements in the array

public static void displayReverse(int[] arr) {

 System.out.print("All integers in the array in reverse : ");

 for (int i = arr.length - 1; i >= 0; i--) {

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

 }

 System.out.println();

}

// Method to print out the sum of the elements in the array.

// The method receives only a single parameter which is the array.

// Declare a variable called sum to hold the sum of the elements

// Initialize sum to zero

// Loop through the array and cumulatively add each element to sum

// Print out the sum at the end of the loop

public static void sum(int[] arr) {

 int sum = 0;

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

  sum += arr[i];

 }

 System.out.println("The sum of the integers in the array is " + sum);

}

// Method to print all values in the array that are less than a limiting

// argument.

// The method has two parameters - the array and the limiting argument.

// Loop through the array and at every cycle,

// check if the current array element is less than the limiting argument.

// If it is, print it out. Else continue

public static void lessThan(int[] arr, int limitingargument) {

 System.out.print("All values less than the limiting argument (" + limitingargument + ") are: ");

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

  if (arr[i] < limitingargument) {

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

  }

 }

 System.out.println();

}

// Method to print all values in the array that are higher than the average of

// the array.

// The method has one parameter - the array.

// First, calculate the average of the array elements.

// Loop through the array and at every cycle,

// check if the current array element is greater than the average.

// If it is, print it out. Else continue

public static void higherThan(int[] arr) {

 int sum = 0;

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

  sum += arr[i];

 }

 double average = sum / arr.length;

 System.out.print("All values higher than the calculate average (" + average + ") is ");

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

  if (arr[i] > average) {

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

  }

 }

 System.out.println();

}

}

Explanation:

The program has been written in Java.

Please go through the comments in the code for explanation.

The source code has also been attached to this response.

Hope this helps!

Download java
You might be interested in
DRIVER ED
julsineya [31]

This is true. Motorcycles are much smaller than cars and therefore more easily can slip into a blind spot. Motorcyclists also have less protection than other drivers and would likely suffer more injury in a collision.

4 0
4 years ago
Read 2 more answers
"In about 100 words, discuss the technologies that Walmart’s trucking fleet might use to better manage their operations. Include
Sergio [31]

Answer:

The answer to this question can be described as follows:

Explanation:

The term Tracking technology is divided into two parts first tacking and technology, in which Tracking is being used to increase or decrease the frequency of both the document on one page by increasing or growing the distance among letters, and technology is how we use engineering for intensive purposes.

  • The technology of tracking It is very the fusion of many innovations, that can also be combined to build machines, which follow the material, stock or even the fleets of vehicles. A delivery of situation-based services to wireless networks can be achieved by similar programs.
  • The principal aim is to look at individuals or items on the movement and to provide for the further analysis a timely ordered locational sequence of details.
3 0
3 years ago
I'm pretty sure most of you know squid game, right? Well, are the actors really dying? or is it just CGI or effects? Because it'
valentinak56 [21]

Answer:

不,他们在制作系列时使用了特殊效果。

可以看幕后!!

6 0
3 years ago
Read 2 more answers
A(n) ________ software installation enables you to decide which features you want to install on the hard drive
Mazyrski [523]
<span>An element in the Excel window that displays the value or formula contained ... which you can specify the type of calculation you want to perform in an Excel formula are: ..... installs all the most commonly used files to your computer's hard drive. Full. A(n) ______ software installation enables you to decide which features you ...</span><span>
</span>
5 0
4 years ago
What part of speech is contend
Amiraneli [1.4K]
Assuming the context, it would be considered a verb.

ie: "She contended to me that I was not acting maturely." 
7 0
3 years ago
Other questions:
  • What is the main idea of this article? Please someone help me. I will give brainliest answer
    7·1 answer
  • An array of Strings, names, has been declared and initialized. Write the statements needed to determine whether any of the array
    9·1 answer
  • Database software lets the user sort information alphabetically, chronologically, or numerically. Which is NOT a commonly used d
    7·1 answer
  • 6.3 code practice: Question Edhesive
    8·1 answer
  • What is a resume?A collection of all your professional and artistic works.A letter which explains why you want a particular job.
    6·1 answer
  • I have a variable and set it equal to 5. 1 then send it as an argument to a function that adds 5 to the variable passed in. Outs
    9·1 answer
  • Which web design concept is most closely related to elements that symbolize the real world​
    5·1 answer
  • And tags are examples of stand - alone tags.
    15·1 answer
  • Discuss the causes ,symptoms, preventive measures and treatment of AIDS​
    6·2 answers
  • The mainframe computer are the ____ and most ____ computers..​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!