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
5 QUESTIONS, BRAINLIEST, PLEASE ANSWER
lara [203]

Answer:

1. Input() is the correct answer

2.Most programming languages have a data type called a string, which is used for data values that are made up of ordered sequences of characters, such as "hello world". A string can contain any sequence of characters, visible or invisible, and characters may be repeated. ... A string can be a constant or variable .

3.The int() function converts the specified value into an integer number.

4.CandyCost = int(input("How much is the candy?"))

5.int()

ANSWERS

8 0
3 years ago
Define file manager
Mama L [17]

Answer:

A file manager or file browser is a computer program that provides a user interface to manage files and folders.

3 0
3 years ago
When data is being prepared for transmission onto the network, it is broken into small pieces and a header and trailer are added
Archy [21]

Answer:

The correct answer to the following question will be "Encapsulation".

Explanation:

  • Encapsulation relates to the pooling of data with techniques used by the database or the limitation of immediate access to many of the elements of the entity.
  • As data is being processed for transfer to the network, it's split into tiny pieces and a trailer and header are attached to each piece to help determine it.
  • It is a method of shielding data facts and preserving the object's data and actions from abuse by certain objects.

Therefore, Encapsulation is the right answer.

8 0
3 years ago
Write the definition of a function named alternator that receives no parameters and returns true the first time it is invoked, r
Nataly [62]

Answer:

The solution code is written in C++

  1. bool STATUS = true;
  2. bool alternator ()
  3. {
  4.    if(STATUS){
  5.        STATUS = false;
  6.        return true;
  7.    }else{
  8.        STATUS = true;
  9.        return false;
  10.    }
  11. }

Explanation:

We need a global variable to track the status of true or false (Line 1).

Next, create the function alternator (Line 2) and then check if current status is true, set the status to false but return the previous status boolean value (Line 5-6). At the first time of function invocation, it will return true.

The else block will set the STATUS to true and return the false (Line 7-9).

3 0
2 years ago
What is the difference between soft copy output devices and hard copy output devices​
Alecsey [184]

the output printed on the paper is called hardcopy output. some examples are printer and plotter.

the output produced on display screen and audio sound is called soft copy output. some examples are moniter and speaker.

3 0
3 years ago
Other questions:
  • For what show did the actor, whose star is located at 6667 Hollywood Boulevard, earn an Emmy Award for Outstanding Supporting Ac
    10·2 answers
  • When did internet came to existence?
    12·1 answer
  • What are some causes of the number of bytes on the wire exceeding the number of bytes being captured?
    6·2 answers
  • What is the very first thing a user usually must do to gain access to a secure computer?
    7·1 answer
  • Given the following function definition, what modifications need to be made to the search function so that it finds all occurren
    7·1 answer
  • What is the difference between line art and continuous tone copy?
    14·1 answer
  • What is the most common way for an attacker outside of the system to gain unauthorized access to the target system?
    15·1 answer
  • Suppose we perform a sequence of n operations on a data structure such that if some condition C(k) holds then the kth operation
    7·1 answer
  • What should be done if a system cannot boot from the hard drive?
    14·1 answer
  • Describe how being a global citizen in the world of advanced technology can be beneficial to your success in meeting your person
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!