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
"Random Bars" is considered to be a Transition style<br> O True<br> O False
Vesnalui [34]
True….hope it helps love
8 0
2 years ago
Which of these is not a combination of a keyboard and percussion musical instrument?
Sergio [31]

Answer:

The Harmonium is not a combination of a key board and percussion musical instrument.

Explanation:

The Harmonium is not a combination of a key board and percussion musical instrument.

A harmonium, also called a "melodeon", "reed organ" or "pump organ", is a keyboard instrument that is a lot like an organ. It makes sound by blowing air through reeds, which are tuned to different pitches to make musical notes.

3 0
2 years ago
I wiil mark brainlist ​
Darina [25.2K]
CAD is the answer you require, but it may also be Spread sheet

Hope this helped ♥︎
5 0
3 years ago
Technician A says that automotive engine blocks are usually classified by the number of cylinders the block. Technician B says t
viva [34]
<span>A. Both Technicians A and B is the answer</span>
8 0
3 years ago
Is it possible to do Agile project in Waterfall methodology?
MariettaO [177]
Yes, it could be possilbe
5 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program for playing tic tac toe. Two players take turns marking an available cell in a 3 X 3 grid with their respective
    15·1 answer
  • A _________ is a copy of one or more files (or entire storage devices) that is made in case the originals become lost or damaged
    5·1 answer
  • Does functionality provided by the app play an important role in a decision to
    13·1 answer
  • A student is curious about how a Web site appears on his computer screen. On a piece of paper,
    9·1 answer
  • One of the first signals that an organization is making progress in the development of its IR program, specifically in the devel
    6·1 answer
  • You have a web application hosted in AWS cloud where the application logs are sent to Amazon CloudWatch. Lately, the web applica
    7·1 answer
  • What is the output?<br> &gt;&gt;&gt; password = "sdf#_356"<br> &gt;&gt;&gt; password.isalnum()
    8·2 answers
  • What is the codebook?
    6·1 answer
  • Which keyboard shortcut cuts information to the clipboard?
    14·1 answer
  • True or false. The send e-mail feature, listed under tools, will allow you to send an e-mail to your instructor and to fellow st
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!