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

Write a method, including the method header, that will receive an array of integers and will return the average of all the integ

ers. Be sure to use the return statement as the last statement in the method. A method that receives an array as a parameter should define the data type and the name of the array with brackets, but not indicate the size of the array in the parameter. A method that returns the average value should have double as the return type, and not void. For example: public static returnType methodName(dataType arrayName[]) 3 The array being passed as a parameter to the method will have 10 integer numbers, ranging from 1 to 50. The average, avgNum, should be both printed in the method, and then returned by the method. To print a double with 2 decimal points precision, so use the following code to format the output: System.out.printf("The average of all 10 numbers is %.2f\n", avgNum);
Computers and Technology
1 answer:
Burka [1]3 years ago
6 0

Answer:

The method is as follows:

public static double average(int [] arrs){

    double sum = 0,avgNum;

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

        sum+=arrs[i];

    }

    avgNum = sum/arrs.length;

    System.out.printf("The average of all numbers is %.2f\n", avgNum);

    return avgNum;

}

Explanation:

This defines the method

public static double average(int [] arrs){

This declares sum and avgNum as double; sum is then initialized to 0

    double sum = 0,avgNum;

This iterates through the array

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

This adds up the array elements

        sum+=arrs[i];     }

This calculates the average

    avgNum = sum/arrs.length;

This prints the average to 2 decimal places

    System.out.printf("The average of all numbers is %.2f\n",

avgNum);

This returns the average to main

    return avgNum; }

You might be interested in
Color of seagrass beds on navigational charts? Please quickly
Nadya [2.5K]
Hello! The color of seagrass beds on navigational charts are brown, because they are in shallow areas and it helps you know the locations of them.
5 0
3 years ago
Which method would provide you with pictures you could upload from a disc that you insert in your computer?
max2010maxim [7]
The correct answer is c. IG: @helloimlalo
4 0
4 years ago
a certain kind of fish in the ocean eats only algae. a seal eats this fish a bear eats the seal .when the bear dies,it’s recycle
STatiana [176]

Answer:seal

Explanation:

4 0
3 years ago
An integer is said to be a perfect number if the sum of its divisors, including 1 (but not the number itself), is equal to the n
kirill115 [55]
True

explanation: bc it is
8 0
3 years ago
Which practice is the best option for desktop security?
ziro4ka [17]
You should make a unique password and change it daily
6 0
3 years ago
Read 2 more answers
Other questions:
  • Smartphones can have virtual keyboards or physical keyboards. What are 3 advantages and disadvantages to each one?
    13·1 answer
  • Which part of an I-statement involves a description of your needs or feelings?
    12·1 answer
  • Prodeff, an online project management software, is available at a price of $1 per use. The software requires the user to enter t
    13·1 answer
  • If you “bury” a story on Digg, what have you done
    10·1 answer
  • The amount of vertical space between lines within paragraphs
    9·1 answer
  • When you're working with a word processing document and you press the del key, what happens?
    5·1 answer
  • Step into my world
    7·2 answers
  • What is another name for repetition in programming?
    11·1 answer
  • 3 uses of Microsoft word in hospital
    10·1 answer
  • you have been tasked with configuring a digital information station in the office's lobby. guests will be able to use the statio
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!