answer.
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
Cerrena [4.2K]
2 years ago
3

Given a variable temps that refers to a list, all of whose elements refer to values of type float, representing temperature data

, compute the average temperature and assign it to a variable named avg_temp. Besides temps and avg_temp, you may use two other variables -- k and total.
Computers and Technology
1 answer:
steposvetlana [31]2 years ago
8 0

Answer:

The solution code is written in Java. This is because Java is a type-strict language that enable us to assign a specific data type (e.g. float) to the variable that match the problem scope stated in the question.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        float temps[] = { 12.1f, 5.4f, 8.9f, 3.2f, 15.5f };
  4.        
  5.        float avg_temp;
  6.        float total = 0;
  7.        for(int k = 0; k < temps.length; k++)
  8.        {
  9.            total += temps[k];
  10.        }
  11.        avg_temp = total / temps.length;
  12.        System.out.println(avg_temp);
  13.    }
  14. }

Explanation:

Firstly, declare a temps array with float type and assigns it with a random set of temperature values (Line 5). All the random temperature are float values (decimal numbers).

Next, declare another two variables avg_temp (Line 7) and total (Line 8) with float type. The avg_temp will hold the average of  temperatures from the array whereas the total will hold the total temperatures.

Prior to calculating the average temperature, we need to get the total of temperature. This is done by creating a for-loop and iterate through each element from the array and add it to the variable total (Line 10 -13).

Once we get the total of temperature, divide the variable total with the length of the array temps (which is equivalent to the number of temperature values in the array) and assign it to variable avg_temp ( Line 15).

At last, we can print out the value of avg_temp to verify the output (Line 17).

You might be interested in
Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences
Nitella [24]

Answer:

//Method definition

//Method receives a String argument and returns a String value

public static String removeDuplicates(String str){

       //Create a new string to hold the unique characters

       String newString = "";

       

       //Create a loop to cycle through each of the characters in the

       //original string.

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

           // For each of the cycles, using the indexOf() method,

           // check if the character at that position

           // already exists in the new string.

           if(newString.indexOf(str.charAt(i)) == -1){

               //if it does not exist, add it to the new string

               newString += str.charAt(i);

           }  //End of if statement

       }   //End of for statement

       

       return newString;   // return the new string

   }  //End of method definition

Sample Output:

removeDuplicates("bookkeeeeeper") => "bokeper"

Explanation:

The above code has been written in Java. It contains comments explaining every line of the code. Please go through the comments.

The actual lines of codes are written in bold-face to distinguish them from comments. The program has been re-written without comments as follows:

public static String removeDuplicates(String str){

       String newString = "";

       

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

           if(newString.indexOf(str.charAt(i)) == -1){

               newString += str.charAt(i);

           }

       }

       

       return newString;

   }

From the sample output, when tested in a main application, a call to removeDuplicates("bookkeeeeeper") would return "bokeper"

7 0
2 years ago
When a button is selected, the computer processes the code contained in the buttons ____ event procedure?
My name is Ann [436]
The event is called keypress, usually the code is referred to as callback.
6 0
2 years ago
What does the binary odometer show about representing large numbers​
Gelneren [198K]

Answer and Explanation:

The binary odometer represents the large number to judge that what happened when there is a large number that gets too large

Here we visit the level 2 of the binary odometer widget in the chapter of Code studio

This represents a widget that reproduced an odometer of a car in which the tracking of a device could be known that how much far the car is driven with respect to the miles or kilometers

7 0
2 years ago
Enter an input statement using the input function at the shell prompt. When the prompt asks you for input, enter a number. Then,
Pavel [41]

Answer:

<u>Explanation:</u>

An input statement using the input function at the shell prompt is as follows:

If a prompt asks for a input, a number is to be added

num = input ('Number: ')

num = num + 1

print(num)

Explanation of results: This gives error at line num= num + 1 as cannot convert int object to str implicitly

8 0
2 years ago
1. Do you consider Facebook, MySpace, and LinkedIn forms of disruptive or sustaining technology? Why?
Mrrafil [7]
It mainly just depends on if you "misuse" them.
8 0
2 years ago
Other questions:
  • Explain why companies design products with a planned obsolescence
    14·1 answer
  • A mouse is known as a _____ device that is able to detect motion in relation to the surface and provides an onscreen pointer rep
    6·1 answer
  • Following are groups of three​ phrases, which group states three ways to improve your​ concentration?
    13·1 answer
  • Days of the week are represented as three-letter strings ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"). Write a javaScript f
    14·1 answer
  • Which of the registration patterns is best suited for complex architecture? A. Client side discovery pattern B. Third party regi
    13·1 answer
  • (a) Show how to use (the Boolean formula satisfiability program) satisfiable num (and substitute) to find a satisfying assignmen
    9·1 answer
  • This program will output a right triangle based on user specified height triangle_height and symbol triangle_char. (1) The given
    9·1 answer
  • php Exercise 3: Function Write a function named word_count that accepts a string as its parameter and returns the number of word
    5·1 answer
  • 1. Used ____________ must be hot drained for 12 hours or crushed before disposal.
    15·1 answer
  • Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lowe
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!