Create a Java static method named getAverageOfFours that takes an array of integers as a parameter and returns the average of the 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.

Answers

Answer 1

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.


Related Questions

In Online Data Extraction data is extracteddirectly from the ------ system itself.o Hosto Destinationo Sourceo Terminal

Answers

Answer:

system itself.

Explanation:

In Online Data Extraction data is extracted directly from the system itself.

Write a C++ program that determines if a given string is a palindrome. A palindrome is a word or phrase that reads the same backward as forward. Blank, punctuation marks and capitalization do not count in determining palindromes. Here is some examples of palindromes:

Radar
Too hot to hoot
Madam!I'm adam

Answers

A C++ program to determine if a given string is a palindrome involves converting the string to the same case, removing non-alphanumeric characters, and then checking if the string is equal to its reverse. Below is a sample code that performs these steps:

#include

#include

#include

#include

bool isPalindrome(const std::string& str) {

   std::string sanitized;

   for (char ch : str) {

       if (std::isalnum(ch))

           sanitized += std::tolower(ch);

   }

   std::string reversed = sanitized;

   std::reverse(reversed.begin(), reversed.end());

   return sanitized == reversed;

}

int main() {

   std::string input;

   std::cout << "Enter a string to check if it is a palindrome: ";

   std::getline(std::cin, input);

   bool result = isPalindrome(input);

   if(result) {

       std::cout << "The string is a palindrome." << std::endl;

   } else {

       std::cout << "The string is not a palindrome." << std::endl;

   }

   return 0;

}

In the above program, the function isPalindrome takes a string and creates a sanitized copy by iterating over each character, checking if it is alphanumeric (ignoring spaces and punctuation), and converting it to lowercase. After constructing the sanitized string, it creates a reversed version and compares the two. The main function reads a string from the user, calls the isPalindrome function, and outputs the result.

Under Rule 504 ofRegulation D, a company can sell up to ______ of securitiesin

any 12-monthperiod.

a. $50,000

b. $100,000

c. $500,000

d. $1,000,000

Answers

Answer:

5,000,000 (5 million) of securities in any 12-month period.

Explanation:

Based on my extensive research on regulations. Rule 504 of Regulation D provides an exemption for having to register under the federal securities laws. This is usually for companies that are in business with products or services that are considered as securities or commodities. This Rule allows a company to sell up to 5,000,000 of securities in any 12-month period.

This answer is not part of the list of available answers but it is correct. Those answers may be outdated.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

True / False
The architecture of a computer determines its machine language.

Answers

Answer: True

Explanation:

The architecture of the computer determine the processor and it determines whether we will have fixed length instructions or variable length instructions.

We have CISC and RISC architectures which uses different types of instructions and the data are processes in different machine languages.

In a ____ queue, customers or jobs with higher priorities are pushed to the front of the queue.

A.
structured

B.
divided

C.
priority

Answers

Answer: In a priority queue, customers or jobs with higher priorities are pushed to the front of the queue.

Explanation:

A queue is an abstract data type which is an ordered set of elements. The elements are served in the order in which they join the queue. The first element which was put in the queue is processed first.  

The operations performed on queue data type are dequeue and enqueue.

Dequeue refers to removal of the first element from the queue after it has been serviced.

Enqueue refers to the arrival of new element when the element is added at the end of the queue.

A priority queue is another implementation of a queue. All the elements in a priority queue are assigned a priority. The element with the higher priority is served before the element with a lower priority. In situations of elements having same priority, the element is served based on the order in which the element joined the queue.

In programming, a priority queue can be implemented using heaps or an unordered array. Unordered array is used based on the mandatory operations which are performed on the priority queue.

The mandatory operations supported by a priority queue are is_empty, insert_with_priority and pull_highest_priority_element. These operations are implemented as functions in programming.

The is_empty confirms if the queue is empty and has no elements.

The insert_with_priority puts the new element at the appropriate position in the queue based on its priority. If the priority of the element is similar to the priority of other element, the position of the new element is decided based on the order of joining the queue.

The pull_highest_priority_element pulls the element having the highest priority so that it can be served before other elements. The element having the highest priority is typically the first element in the priority queue.

In operating system, priority queue is implemented to carry out the jobs and/or tasks based on their priority.

What are the attributes of agood Software Test?

Answers

Answer:

The features of a software test to be efficient are basically used to measure the quality control so that prevention can be provided from the errors or sort of defects. These characterstics are used for quality assurance and focuses on detecting the efficiency of the products and  its services.  

The some characteristics of a good software test are as follows:

Testing-ability - System should reliable on detection of any failure or error.

Efficiency -should be reliable enough to carry out tasks .

Reusability - Should be useful for several purpose at different times.

Maintainability - maintenance should be easy and efficient.

What is the difference between an argument and a parameter variable?

Answers

Answer:

The value enter in the function calling is called argument. Argument passed to function.

The variable declare in the function to capture the pass value from the calling function is called parameters.  

Explanation:

Argument is used in the calling function and parameter is used in the defining the function.

for example:

//create the function

int count(parameter_1, parameter_2,.....)

{

  statement;

}

count(argument_1. argument_1,.....);   //call the function

Write each of the following decimal values in binary. (Can please show me how you did arithmetic you to perform the conversion.)
47
14
81
102
241

Answers

Answer:

47 → 101111

14 → 1110

81 → 1010001

102 → 1100110

241 → 11110001

Explanation:

There are two ways to calculate binary equivalent of decimal values:

Divide the number by 2 as in the image, keep the reminder to right. then divide the divisor by 2 and keep the reminder to right and so on. Then read the reminders from top to bottom.Or you can start putting 1 at the nearest power of 2 that is smaller than decimal integer, then subtract that value from the decimal integer. Again put 1 at nearest power of 2 and so on.

       e.g.

       For 102, we put 1 at 64. than 102[tex]-[/tex]64 = 38

                      then put 1 at 32, now 38 [tex]-[/tex] 32 = 6.

                      then put 1 at 4, now 6 [tex]-[/tex] 4 = 2.

                      then put 1 at 2, now 2[tex]-[/tex]2 = 0.

                      so put 0 at 1 and all other places except those where we put 1.

. If you executean infinite recursive function on a computer it will executeforever.
a. True
b.False

Answers

Answer:

b. False

Explanation:

If you execute an infinite recursive function on a computer it will NOT execute forever.

Write a program in which you input three numbers they canhave decimals so float values and the program gives you the minvalue out of the three. Please need asap thank you

Answers

Answer:

Following is the c++ code:-

#include <bits/stdc++.h>

using namespace std;

int main() {

   float a,b,c;//declaring three float variables..

   cout<<"enter values"<<endl;

   cin>>a>>b>>c;//taking input..

   float mi=min(a,b);//finding minimum in a and b..

   mi=min(mi,c);// finding minimum from mi and c.

   cout<<mi<<endl;//printing the answer.

return 0;

}

Explanation:

I have taken three float variables to hold the values.

then I am finding the minimum in a and b and storing it in mi.

Then finding minimum from mi and c so we will get our final minimum number.

What is the output after the following code executes?

int x=10; if ( ++x > 10 ) {

x = 13;

}

cout << x;

Answers

Answer:

13

Explanation:

First understand the meaning of ++x, it is a pre-increment operator.

it means, it increase the value first than assign to the variable.

For example:

x=10

then after executing  ++x, the value of x is 11.

it increase the value and assign to x.

In the question:

The value of x is 10. After that, program moves to the if condition and check for condition (++x > 10) means (11 > 10) condition true.

then, 13 assign to x.

After that value of x is printed as 13.

Final answer:

The C++ code increments the variable x to 11 due to the pre-increment in the if statement, then changes x to 13 within the if block. Thus, the output of the code, when executed, is 13.

Explanation:

When the C++ code provided is executed, the statement int x=10; initializes the variable x with the value 10. The subsequent if statement checks if ++x > 10, where ++x is a pre-increment operation that increases x by 1 before the comparison. Since x is incremented to 11 before the comparison, the if block is executed, setting x to 13. The cout << x; statement then outputs the value of x, which at this point will be 13.

The characters << indicate that the value to the right is to be sent to the cout, which identifies the standard output stream. For cout to work, we need the inclusion of the iostream header file and the usage of the using namespace std; directive.

All of the followingshould be followed by entrepreneur for being effective

leader,EXCEPT:

a. Show respect foremployees

b. Show concern foremployees’ welfare

c. Try to do everythinghimself

d. Encourage and praiseothers

Answers

Answer:

C - Try to do everything himself

Explanation:

It is usually never advisable for an entrepreneur to attempt to do everything themselves. Delegation (assigning a task to a subordinate) is an important aspect of entrepreneurial leadership, this benefits the entreprenuer himself and allows his employees to feel a sense of confidence because they were trusted witht the task and it is a chance to show what they are capable of.

What is the difference between“Internetwork and the Internet”?

Answers

Answer: Inter-network-It is the network that gets created joining of many networks together and form a individual large network .

Internet- it is the global network that contains that contains the collection of all the networks.

Explanation:

Internet is the network at a global level which has the access to connect the various computer network together and inter-network is the network having the combination of many network together to form a single unit of network  .Internet usually forms the connection using routers , servers etc and inter-network uses LAN's ,PAN's etc. to form the connection

Find the second largest and second smallest element in a given array. You can hardcode/declare the array in your program.

Answers

Answer:

Program for Second largest in an array:-

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int f,s,n; //declaring 3 variables f for first largest s for second largest n is size.

    cin>>n;//taking input size of the array.

    if(n<2)//n should be greater than 2..

    cout<<"n should be greater than 2"<<endl;

    int a[n];// array of size n.

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

    {

        cin>>a[i];

    }

   f = s = INT_MIN;//initialising f and  s with minimum value possible.

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

   {  

       if (a[i] > f)  

       {  

           s = f;  

           f = a[i];  

       }  

       else if (a[i] > s && a[i] != f)  

           s = a[i];  

   }  

   if (s == INT_MIN)  

       cout<<"No second largest exists"<<endl;

   else

       cout<<"Second largest element is :"<<s;

       return 0;

}

Program for second smallest element is:-

#include <bits/stdc++.h>  

using namespace std;  

int main()  

{  

int f,s,n; //declaring 3 variables f for first smallest s for second smallest n is size.  

cin>>n;//taking input size of the array.  

if(n<2)//n should be greater than 2..  

cout<<"n should be greater than 2"<<endl;  

int a[n];// array of size n.  

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

{  

cin>>a[i];  

}  

f = s = INT_MAX;//initializing f and s with maximum value possible.  

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

{  

if (a[i]<f)  

{  

s = f;  

f = a[i];  

}  

else if (a[i] < s && a[i] != f)  

s = a[i];  

}  

if (s == INT_MAX)  

cout<<"No second smallest exists"<<endl;  

else  

cout<<s;//it is the second smallest element...  

return 0;  

}

Explanation:

For Second largest:-

1. Declare 3 variables f, s and n. where n is size the array f is first largest and s is second largest.

2. Initialize f and s with minimum value possible.

3. Iterate over the array a and do the following steps:-

   1.If element at ith position is greater than f. Then update f and s.

   s=f and f=a[i].

   2.If the element is between s and f then update s as.

   s=a[i].

4. Print s because it is the second largest in the array.

For Second smallest:-

1. Declare 3 variables f, s and n. where n is size the array f is first smallest and s is second smallest.

2. Initialize f and s with minimum value possible.

3. Iterate over the array a and do the following steps:-

   1.If element at ith position is smaller than f. Then update f and s.

   s=f and f=a[i].

   2.If the element is between s and f then update s as.  

   s=a[i].  

4. Print s because it is the second smallest in the array.

Which of the following electronic payments is ideal for micropayments?

A. purchasing cards

B. smart cards

C. none of the methods listed

D. electronic checks

Answers

Smart cards are ideal for micropayments.

ETL stands for ---------------o Extract, transform and loado Extended transformation loadingo Enhanced logical transformation

Answers

Answer:

Extract, transform, and load

Explanation:

ETL stands for extract, transform, and load.

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.



1. do-while

2. while

3. for

4. infinite

5. None of these

Answers

Answer:

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.: for - 3.

Infinite means not stop. Something that keeps going and going! So the answer would have to be 4 :)

What is transaction? Differentiate between pre-emptiveand non pre-emptive transactions

Answers

Answer: Transaction is the process of processing information in a standalone system or distributed system. There are two basic types of systems which are preemptive and non preemptive transactions.

Explanation:

Transaction can be complete successfully or it can fail but it can never be partially completed. Computer processes which completes in its entirety or  does not complete at all are termed as processes.

Preemptive processes are those where the cpu is allotted to a process for a definite time . The cpu can be given to another process if it has higher priority.

Whereas in non preemptive processes the cpu once allotted to a process cannot be assigned to another process until job is finished for the first process.

Which of the following is used to verify a user's identity? A) Identification B) Authentication C) Validation D) Authorisation E) Accountability

Answers

Answer:

A? "A means of proving a person identity"

Explanation:

Given an array of integers an). The array is already NOT write C++ statements to fill the array eye write C++ statements that print to the screen how many values in the how many values are odd. In addition, the statements output to the scre the array that are even. s

Answers

Answer:

#include<iostream>

using namespace std;

int main () {

   int n;

   int odd=0,even=0;

  cout<<"Enter the number of element store in the array: ";

  cin>>n;

  int arr[n];

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

     cin>>arr[i];

  }

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

       if(arr[i]%2==1){

           odd++;

       }else{

           even++;

       }

  }

  cout<<"The number of odd values is: "<<odd<<endl;

  cout<<"The number of even values is: "<<even<<endl;

}

Explanation:

Include the library iostream for input/output.

Create the main function and declare the variables.

Then, print the message on the screen and store the value enter by the user for the size of the array. After that, take a for loop and store the values in the array enter by the user.

then, take a for loop for traversing to the array and check the condition for odd and even by using if-else statement.

for odd: If odd values divided by 2 it gives 1 remainder.

for even: If even values divided by 2 it gives zero remainder.

if condition true, then update the counter.

finally, print the result.

What is stand-alone LDAP server?

Answers

Answer:

A stand-alone LDAP server is defined as to remove the load from a server that does multi function tasks. It is more efficient when we use one or more LDAP configurations .

Light weight Directory Access Protocol (LDAP) is a client and server protocol used for accessing directory data. It  helps in reading and editing the directories over IP networks and runs directly over Transmission control protocol and internet protocol used simple string format for transferring of data.

What applications work best with multiplexing?Why?

Answers

Answer:

Multiplexing is the process of combining multiple analog and digital signal into one signal over a shared medium and it is most efficient service, which is provided by the transport layer protocol. The main purpose of multiplexing is that signal are transmitted efficiently.

It contains applications as:

Client-server Application

Many to single client-server application

Many to many client-server application

Many client to many server application is the best because it is improving server application and processing a client request within a group on any server.

Which keyboard shortcut is typically used to move to the previous entry box?

A. Ctrl+Enter
B. Tab
C. Enter
D. Ctrl+Tab

Answers

Answer:

D. Ctrl+Tab

Explanation:

The Ctrl+Tab shortcut is typically used to move to the previous entry box.

The purpose of a database is to help people stop using spreadsheets.

Answers

Answer:

Yes, the purpose of a database in a way is to stop people from using spreadsheets but, it is also so much more.

Explanation:

Databases are a vastly improved form of a spreadsheet. They allow Computer Scientists to automatize a company's information. Giving them the ability to instantly add, retrieve, and modify specific information within a database of hundreds or even thousands of entries. All this with little or no human input. Thus saving a company time and money as opposed to using a regular spreadsheet which requires manual input from an employee.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

Write a program which prompts user to enter a character, if the user presses „Z‟, the program asks user to enter a number. In this case the program implements 5-input majority voting logic which is explained as follows.The value of the number represented by the five leftmost bits of Register-B is tested. If the number of logic '1' bits (in the 5 leftmost bits) is greater than the number of logic '0' bits, the program should output: "The number of 1’s in the 5 left most bits is greater than the number of 0’s". If the number of logic '0' bits (in the 5 leftmost bits) is greater than the number of logic '1' bits, the program should output: "The number of 0’s in the 5 left most bits is greater than the number of 1’s"

Answers

I’m pretty sure the answer is A

What will the following C code print out?

int x = 7, y = 5;

if (x > 5)

if (y > 5)

printf(“x and y are > 5”);

else

printf(“x is <=5”);
a) “x and y are > 5”

b) “x is <=5”

c) nothing will be printed

Answers

Answer:

x is <=5

Explanation:

If-else is the statement that is used to execute the statement when the condition is true.

syntax:

if(condition){

    statement;

}else{

    statement;

}  

if we do not provide the curly bracket, still the statement is valid.

in the question, x =7 and y=5

then, check the condition 7 > 5 condition true. it moves to the next if statement and check 5 > 5, condition false. Then it moves to the else part and executes the statement.

and print the output "x and y are > 5".

How do you return a value from a function?

Answers

Answer:

return instruction used to return a value from a function.

Explanation:

Function is a block of statement which perform the special task.

Syntax for define a function:

type name(parameter_1, parameter_2,...)

{

  statement;

return variable;

}

In the syntax, type define the return type of the function. It can be int, float, double and also array as well. Function can return the array as well.

return is the instruction which is used to return the value or can use as a termination of function.

For return the value, we can use variable name which store the value or use direct value.

Write a program to print out the digits of a number in English. For example, if the number is 153, the output should be “One Five Three.” This program should allow users to input the number by using keyboard

Answers

Answer:

#include <bits/stdc++.h>

using namespace std;

string value(int i)//function return the string of the integer..

{

  if(i==0)

  return "Zero";

  if(i==1)

  return "One";

  if(i==2)

  return "Two";

  if(i==3)

  return "Three";

  if(i==4)

  return "Four";

  if(i==5)

  return "Five";

  if(i==6)

  return "Six";

  if(i==7)

  return "Seven";

  if(i==8)

  return "Eight";

  if(i==9)

  return "Nine";

}

int main() {

int n,a[100],c=0;

cout<<"Enter the integer"<<endl;

cin>>n;//taking input of n..

while(n>0)//storing the integer in the array in reverse order..

{

    int digit=n%10;

    a[c++]=digit;

    n/=10;

}

int s=0,e=c-1;

while(s<=e)//reversing the array.

{

    int temp=a[s];

    a[s]=a[e];

    a[e]=temp;

    s++;

    e--;

}

for(int i=0;i<c;i++)//printing the string according to the number..

{

    cout<<value(a[i])<<" ";

}

cout<<endl;

return 0;

}

Output:-

Enter the integer

230

Two Three Zero

Explanation:

I have created a function which returns string according to the integer.So i have taken an array to store the digits of the number and reversing it so the number is stored as it is in the array.Then printing the numbers accordingly.

If a CPU receives theinstruction to multiply the byte-sized values $12 and $3E, thisaction will take place in the ______________ (part of internal CPUhardware) section of the CPU.

Answers

Answer: Arithmetic and logic unit(ALU)

Explanation:  In central processing unit (CPU) , there are two main units CU(control unit) and ALU (arithmetic and logic unit) . ALU is responsible for any sort arithmetic and logical operation in the processor.This unit can perform mathematical operation like addition , multiplication divide , logical and many more. So the given operation of multiplication in the question will be done bu ALU of the CPU.

Discuss briefly general-purpose graphicsprimitives that contain 2D graphics library.

Answers

Answer:

  General purpose graphics primitives that contain 2D graphic library as, it is used in graphics processing unit which typically manage computation for computer graphics. Graphic primitives contain basic element such as lines and curves. Modern 2D computer graphic system that operate with primitives which has lines and shapes. All the elements of graphic are formed from primitives.

Other Questions
If point b(6,4) undergoes the following translation (x-8,y+2) what are the coordinates of point b Which of Ahmads expenses will most likely be ranked as variable expenses? Check all that apply.rentdiscretionary spendinggrocerieshealth insuranceelectricity billwater bill Factor completely 3x4 48. 3(x2 4)(x2 + 4) 3(x 2)(x + 2)(x + 2)(x + 2) 3(x 2)(x + 2)(x2 + 4) 3(x 2)(x + 2)(x2 4) what caused the fall of the soviet union There are 8 people on the ballot for regional judges. Voters can vote for any 4. Voters can choose to vote for 0 1 2 3 or 4 judges. In how many different ways can a person vote? write the expression as the sine or cosine of an angle sin(pi/7) cos(x) + cos(pi/7) sin(x) One fifth of the square of a number What achievements during the Pax Romana helped unify the empire? Banyan Co.s common stock currently sells for $53.25 per share. The growth rate is a constant 8%, and the company has an expected dividend yield of 2%. The expected long-run dividend payout ratio is 20%, and the expected return on equity (ROE) is 10.0%. New stock can be sold to the public at the current price, but a flotation cost of 15% would be incurred. What would be the cost of new equity? Do not round intermediate calculations. Round your answer to two decimal places. The mirror check may involve ______________.A. checking that you can see your tires in the mirror B. realigning the mirrors once you get seated C. reinstalling the mirrors every few months D. applying a new layer of anti-glare spray What is the value of "d" after this line of code has been executed? double d = Math.round ( 2.5 + Math.random() ); A. 2 B. 3 C. 4 D. 2.5 Refectories are one of the types of ceramics that have low melting temperature. a)-True b)-False When the average amplitude is non zero then the problemarises is ______________. The following information applies to Jasmine, who is single, for 2017:Salary $56,000Interest income from First Bank of Lexington 1,500Dividends from Watters Company stock 3,000Contribution to a traditional IRA 4,000Loan repayment from her friend 1,000Capital loss from sale of personal vehicle (2,300)Number of potential dependents ?Age 44Jasmine maintains a household for her sister, who has $9,000 from Social Security. In addition, Jasmine's aunt lives with her and has income of $3,000.The personal exemption amount for 2017 is $4,050.Calculate Jasmine's Taxable Income for 2017. The market price of a security is $26. Its expected rate of return is 13%. The risk-free rate is 5% and the market risk premium is 7.0%. What will be the market price of the security if its correlation coefficient with the market portfolio doubles (and all other variables remain unchanged)? Assume that the stock is expected to pay a constant dividend in perpetuity. (Do not round intermediate calculations. Round your answer to 2 decimal places.) Which of the following changes would cause the fusion rate in the Sun's core to increase?-An increase in the core temperature-An increase in the core radius-A decrease in the core temperature-A decrease in the core radius A DSLR camera is made up of two parts. They are 24. Suppose a clay model of a koala bear has a mass of 0.200 kg and slides on ice at a speed of 0.750 m/s. It runs into another clay model, which is initially motionless and has a mass of 0.350 kg. Both being soft clay, they naturally stick together. What is their final velocity? Please help me simplify this fraction. Or is it already in its simplest form? Why do you think the Greekscreated the myth of Demeter andPersephone?