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
Simora [160]
3 years ago
12

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

Computers and Technology
1 answer:
Rus_ich [418]3 years ago
6 0
<h2><u>Answer</u>:</h2>

public class ArrayMethodDemo {

   public static void main (String args[]) {

       int[] numbers = {12, 15, 34, 67, 4, 9, 10, 7};

       int limit = 12;

       display(numbers);

       displayReverse(numbers);

       displaySum(numbers);

       displayLessThan(numbers, limit);

       displayHigherThanAverage(numbers);

   }

   

   public static void display(int[] numbers) {

       

       //Message to be displayed before printing out the numbers

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

       

       //loop through the numbers in the array and print each number

       for(int x: numbers){

           System.out.print(x + " ");

       }

       

       //print a new line

       System.out.println();

   }

   

   public static void displayReverse(int[] numbers) {

       

       //Message to be displayed before printing out the reverse of the array

       System.out.print("Reverse of the array numbers: ");

       

       

       //loop through the array starting from the last index

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

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

       }

       

       //print a new line

       System.out.println();

   }

   

   public static void displaySum(int[] numbers) {

       

       //initialize the sum variable

       int sum = 0;

       

       //loop through the array and add each element to sum

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

           sum += numbers[i];

       }

       

       //print out the sum

      System.out.println("Sum: "  + sum);

       

   }

   

   public static void displayLessThan(int[] numbers, int limit) {

       

       //Text to be displayed before printing values less than the limit

       System.out.print("Values less than limit (" + limit + "): ");  

       //loop through the array and print numbers lower than the specified limit

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

           if(numbers[i] < limit){

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

           }

       }

       

       //print a new line

       System.out.println();

   }

   

   public static void displayHigherThanAverage(int[] numbers) {

       //initialize the average variable

       double average = 0.0;

       

       //initialize the sum variable

       int sum = 0;

       

       

       //loop through the array and add each element to sum

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

           sum += numbers[i];

       }

       

       //calculate the average

      average = sum / numbers.length;

       

       //Message to be displayed before printing the values higher than the average

       System.out.print("Values higher than average (" + average + "): ");

       

       

       //loop through the array and print numbers higher than the calculated average

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

           if(numbers[i] > average){

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

           }

       }

       

       //print a new line

       System.out.println();

   }

   

}

<h2><u>Sample Output:</u></h2>

Numbers in the array: 12 15 34 67 4 9 10 7  

Reverse of the array numbers: 7 10 9 4 67 34 15  

Sum: 158

Values less than limit (12): 4 9 10 7  

Values higher than average(19.0):34 67

<h2>Explanation:</h2>

The code above contains comments explaining important parts of the code. Kindly go through the comments. A sample output, arising from running the application, has also been added to ace understandability.

You might be interested in
4. What two important events occurred early in the formation of the universe?
Annette [7]
C. When they separated it created the big bang
4 0
3 years ago
When inserting a fly in animation what is the first step in the process?
weqwewe [10]

Answer:

you select the element you wish to animate

6 0
3 years ago
Write code which takes a user input of a String and an integer. The code should print each letter of the String the number of ti
Alexus [3.1K]

import java.util.Scanner;

public class JavaApplication70 {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Input a String:");

       String txt = scan.nextLine();

       System.out.println("Input an integer:");

       int num = scan.nextInt();

       String newTxt = "";

       int w = 0;

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

           char c = txt.charAt(i);

           while (w < num){

               newTxt += c;

               w++;

           }

           w = 0;

       }

       System.out.println(newTxt);

   }

   

}

I hope this helps!

7 0
3 years ago
Read 2 more answers
HELP BRAINLIEST FOR RIGHT ANSWER
Scilla [17]

Answer:

true I know this cuz I smart

7 0
3 years ago
Read 2 more answers
Which windows utility should you use to organize the files on your disk to improve efficiency?
olga55 [171]

<span>Disk Defragmenter, is a windows utility that rearranges the records and unused space on the PC's hard disk so that the operating system accesses data more rapidly and projects run quicker. Disk Defragmenter keeps running on a timetable, yet you can likewise break down and defragment your disk and drives manually.</span>

7 0
3 years ago
Other questions:
  • We will pass you 2 inputsan list of numbersa number, N, to look forYour job is to loop through the list and find the number spec
    12·1 answer
  • What is the opening page of a website called?
    9·2 answers
  • In this question, we give two implementations for the function: def intersection_list(lst1, lst2) This function is given two lis
    15·1 answer
  • This problem has been solved!
    8·1 answer
  • When can you access the BIOS setup utility?
    14·1 answer
  • Which component of a word processor displays the name of the document?
    13·1 answer
  • Write a program that asks the p34won to enter their grade, and then prints GRADE is a fun grade. Your program should repeat thes
    7·1 answer
  • If a movie, song, or book is offered for free, is it malware?
    15·1 answer
  • Discuss the advantages and disadvantages of supporting links to files that cross mount points (that is, the file link refers to
    6·1 answer
  • Write a method in pseudocode or Java called move that accepts a boolean[], integer value, and a boolean value. Your method shoul
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!