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
Maurinko [17]
4 years ago
7

Create a Java static method named getAverageOfFours that takes an array of integers as a parameter and returns the average of th

e values in the array that are evenly divisible by 4. Your method must work for an int array of any size. Example: If the array contains [10, 48, 16, 99, 84, 85], the method would return 49.33333.
Computers and Technology
1 answer:
Zepler [3.9K]4 years ago
8 0

Answer:

public class average{

   

   public static float getAverageOfFours(int[] arr){

       

       int n = arr.length;

       float sum = 0;

       int count=0;

       for(int i=0;i<n;i++){

           if(arr[i]%4==0){

               sum = sum+arr[i];

               count++;

           }

       }

       float avg = sum/count;

       return avg;

       

   }

    public static void main(String []args){

       

        int[] array = {10, 48, 16, 99, 84, 85};

       

        float result = getAverageOfFours(array);

        System.out.println("The average is "+result);

    }

}

Explanation:

Create the function with one parameter and return type is float.

Declare the variable and store the size of array. Take a for loop for traversing in the array and and check the element is divisible by 4 or not by using if statement. If condition true take the sum and increment the count.

This process continue until the condition is true.

finally take the average and return it.

Create the main function for calling the function with pass the array as argument and also define the array.

After that print the result return by the function.

You might be interested in
What will be displayed after the following statements execute? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1)
Reika [66]

Answer:

1 1

Explanation:

First we have funny = 7 and serious = 15 .Then after that remainder when serious is divided by 2 is stored in funny that is 1.if condition will be false because funny is equal to 1.else if condition will also be false because it is not 2.So else will be executed and funny =1 and serious =1.

Output=1 1

8 0
4 years ago
Read 2 more answers
If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook?
Helen [10]
Steady sounds like the best answer but that’s tough
5 0
3 years ago
1. You will need to add data to the tables in your design that matches the data in the supplied Excel documents. If your databas
Harlamova29_29 [7]

Answer:

is all about knowing what to do with the data

Explanation:

determine what to do with your data

3 0
3 years ago
4. What is the difference between portrait orientation and landscape orientation? (1.0 points)
Bezzdna [24]

Answer:

Portrait orientation is taller then it is wide, while landscape orientation is wider then it is tall.

Explanation:

3 0
4 years ago
We can draw crescent using ?
Anarel [89]

Answer:

I think it's B

hope this helps

have a good day :)

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Your friends know that you understand a lot about computers, both the technical details of how they operate as well as informati
    12·1 answer
  • If someone receives a shock, or a piece of equipment is throwing sparks or arcing you should try to pull them away from the sour
    7·1 answer
  • What is the area of a triangle whose base is 14 m and whose height is 22 m?
    7·1 answer
  • Based on the type of document you want to create, you must first select the page
    15·2 answers
  • To use Click and type feature can be used to format and enter text graphic and other items
    6·1 answer
  • Useful open source applications include the popular Web browser Mozilla Firefox, the e-mail application Thunderbird, the relatio
    7·2 answers
  • What the defination of electronics capacitor
    11·1 answer
  • Consider the following MARIE Code: 100 If, Load X /Load the first value 101 Subt Y /Subtract the value of Y, store result in AC
    8·1 answer
  • Consider the following first line from a Java method definition.
    13·1 answer
  • How to ignore punctuation before and after a word javascript
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!