Suppose that we want to compute the geometric mean of a list of positive values. To compute the geometric mean of k values, multiply them all together and thenCcompute the kth root of the value. For example, the geometric mean of 2, 5, and 7 is . Use a loop with a sentinel value to allow a user to enter an arbitrary number of values. Compute and display the geometric mean of all the values, excluding the sentinel. (Hint: Math.pow(x, 1.0 / k) will compute the kth root of x.)
What will be an ideal response?
```
int count = 0;
double data = 0.0;
double product = 1.0;
//Scanner reader = new Scanner(System.in);
System.out.println("Enter data values for which" +
" to compute the geometric mean.");
System.out.println("Enter a negative number after");
System.out.println("you have entered all the data values.");
data = reader.nextDouble();
while (data >= 0) {
product = product * data;
count++;
data = reader.nextDouble();
}
System.out.println("The geometric mean is "
+ Math.pow(product, 1.0/count));
```
This code is in Fragments.java.
You might also like to view...
What is the output for the code segment below if the variables have the following values:
phrase word “Testing a string” “sting” int pos = phrase.find (word); if (pos < 5) cout << “at start”; else cout << “at end”;
A_______ begins with a reference to the first node, and each node contains a reference to the next node.
a) doubly linked list. b) singly linked list. c) circular, singly linked list. d) None of the above.
Alpha channels are listed on the ____ panel in Photoshop.
A. Selections B. Channels C. Thumbnail D. Work
Develop a program that inputs one salesperson's items sold for last week, calculates that salesperson's earnings and outputs HTML text that displays that salesperson's earnings.
A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of merchandise in a week receives $200 plus 9% of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value 1 239.99 2 129.75 3 99.95 4 350.89