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
adelina 88 [10]
3 years ago
8

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

play 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. Then, create another array that store 5 integers. Pass the two arrays to a method that will display the integer value(s), if any, that appear in both arrays (note that the two arrays can have no stored values in common). Save the file as ArrayMethodDemo.java.
Computers and Technology
1 answer:
tensa zangetsu [6.8K]3 years ago
3 0

Answer:

  1.     public class Main {
  2.    public static void main(String[] args) {
  3.        int myArray[] = {3, 7, 2, 5, 9,11, 24, 6, 10, 12};
  4.        int myArray2 [] = {1, 2, 3, 4 ,5};
  5.        displayValue(myArray);
  6.        reverseDisplay(myArray);
  7.        displaySum(myArray);
  8.        displayLess(myArray, 10);
  9.        displayHighAvg(myArray);
  10.        displayBoth(myArray, myArray2);
  11.    }
  12.    public static void displayValue(int arr[]){
  13.        for(int i = 0; i < arr.length; i++){
  14.            System.out.print(arr[i] + " ");
  15.        }
  16.        System.out.println();
  17.    }
  18.    public static void reverseDisplay(int arr[]){
  19.        for(int i = arr.length-1; i >= 0; i--){
  20.            System.out.print(arr[i] + " ");
  21.        }
  22.        System.out.println();
  23.    }
  24.    public static void displaySum(int arr[]){
  25.        int sum = 0;
  26.        for(int i = 0; i < arr.length; i++){
  27.            sum += arr[i];
  28.        }
  29.        System.out.println(sum);
  30.    }
  31.    public static void displayLess(int arr[], int limit){
  32.        for(int i = 0; i < arr.length; i++){
  33.            if(arr[i] < limit){
  34.                System.out.print(arr[i] + " ");
  35.            }
  36.        }
  37.        System.out.println();
  38.    }
  39.    public static void displayHighAvg(int arr[]){
  40.        int sum = 0;
  41.        for(int i = 0; i < arr.length; i++){
  42.            sum += arr[i];
  43.        }
  44.        double avg = sum / arr.length;
  45.        for(int i = 0; i < arr.length; i++){
  46.            if(arr[i] > avg){
  47.                System.out.print(arr[i] + " ");
  48.            }
  49.        }
  50.        System.out.println();
  51.    }
  52.    public static void displayBoth(int arr1[], int arr2 []){
  53.        for(int i = 0; i < arr2.length; i++){
  54.            for(int j = 0; j < arr1.length; j++){
  55.                if(arr1[j] == arr2[i]){
  56.                    System.out.print(arr1[j] + " ");
  57.                }
  58.            }
  59.        }
  60.        System.out.println();
  61.    }
  62. }

Explanation:

There are five methods written to solve all the problems stated in the question.

Method 1 : displayValue    (Line 15 - 21)

This is the method that take one input array and use the print() method to display the all the elements in the array.

Method 2: reverseDisplay (Line 23 - 26)

This method will take one input array and print the value in the reverse order. We just need to start with the last index when running the for-loop to print the value.

Method 3: displaySum (Line 31 - 37)

This method will take one input array and use a for-loop to calculate the total of the values in the array.

Method 4: displayLess (Line 39 - 47)

This method will take one two inputs, a array and a limit. We use the limit as the condition to check if any value less than the limit, then the value will only be printed.

Method 5: displayHighAvg (Line 50 - 64)

This method will take one input array and calculate the average. The average will be used to check if any element in the array higher than it, then the value will only be printed.

Method 6: displayBoth  (Line 66 - 75)

This method will take two input arrays and compare both of them to find out if any value appears in both input arrays and print it out.

You might be interested in
Find the errors<br><br> Look to the following code and fix the errors
ivanzaharov [21]
Upper case and lower case problem
7 0
3 years ago
According to our definition in this class, computers are define
mario62 [17]

se definen como un medio de estudio en estos momentos de cuarentena

en la que nos ayuda a sentirnos mas cerca de las clases  

5 0
3 years ago
Write a for loop that displays the following set of numbers: 0,10,20,30,40,50....1000
ELEN [110]
C# program code:

int i = 0
while (i<=1000)
{
console.Writeline("{0}",i);
i = i + 10;
}

Explanation:
First we set variable to initial value. In this example it is 0. Then we enter into while loop. This type of loop executes the code until the condition is fulfilled. In our case while loop checks if i <=1000. It is and then it writes it on the screen. Next step is to increase it by 10. Then it does the same code again.
Last number that will be printed is 1000. After that it will increase i to 1010 and it will exit the loop.
3 0
3 years ago
What is the output of the following JavaScript code?
Kazeer [188]

Answer:

<h2>Arrow function expression var arrowMultiplyBy2 = num => num * 2; If the function takes in only one argument, then the parenthesis around the parameter can be omitted as shown in the code above. ... Code 1 - Output in the following order: undefined 42. </h2>

Explanation:

7 0
3 years ago
Given an alphanumeric string made up of digits and lower case ASCII characters only, find the sum of all the digit characters in
lara31 [8.8K]

Answer:

C++.

Explanation:

#include <iostream>

#include <string>

using namespace std;

////////////////////////////////////////////////////////////////////////////

int sumDigits(string alphanumeric) {

   if (alphanumeric.length() == 1) {

       if ((int(alphanumeric[0]) >= 48) && (int(alphanumeric[0]) <= 57)) {

           cout<<int(alphanumeric[0]) - 48<<endl;

           return (int(alphanumeric[0]) - 48);

       }

       else

           return 0;

   }

   else {

       if ((int(alphanumeric[0]) >= 48) && (int(alphanumeric[0]) <= 57)) {

           cout<<int(alphanumeric[0]) - 48<<endl;

           return int(alphanumeric[0]) - 48 + sumDigits(alphanumeric.substr(1, alphanumeric.length()-1));

       }

       else

           return 0 + sumDigits(alphanumeric.substr(1, alphanumeric.length()-1));

   }

}

////////////////////////////////////////////////////////////////////////////

int main() {

   cout<<"Sum: "<<sumDigits("ab1c2d3e54");

   return 0;

}

3 0
3 years ago
Other questions:
  • A ____ port is a connection in which eight data lines transmit an entire byte of data at one moment in time.​
    10·1 answer
  • Can any existing directory beneath the system root directory be used as a mount point?
    9·1 answer
  • ____________ is a series of numbers that identifies a particular computer. They may or may not be a reliable way to link you to
    14·1 answer
  • If brake fluid boils:
    11·2 answers
  • Answer for a, b, and c
    7·1 answer
  • which internet technology allows businesses to make presentation and share visual aids such as charts and graphs
    14·2 answers
  • Windows OS and Mac OS are examples of which type of operating systems?
    5·1 answer
  • Choose a different well-known company that you know of, and describe its direct and indirect competitors. Describe at least 2 di
    9·2 answers
  • Test if the word mold is stored in the variable word. Computer science.
    9·1 answer
  • Edhesive assignment 1 movie ratings
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!