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 then compute the kth root of the value. For example, the geometric mean of 2, 5, and 7 is
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
C How to Program (8th Edition)
Problem Solving with C++ (9th Edition)
Computer Science: An Overview (12th Edition)
Problem Solving with C++ (10th Edition)
- WATERSORT PROGRAM - JAVA •The aim of Part 2 is to set up the puzzle for the player to solve in Part 3. IMPORTANT NOTE: We are not going to start with 2 empty bottles, but rather with 8 empty slots spread over the 5 bottles as explained in the intro video. Start with 5 empty bottles. Use a random number generator to fill bottles one slot at a time with the colours while keeping 8 slots empty – there is a total of 5*4 = 20 slots – so if we will 12 slots, 8 are free. •Advantage: Easy to create a puzzle with a good mix •Disadvantage: With more colours and bottles and only 2 open bottles for more advanced versions of the game, the result might not be solvable. Start with three sorted bottles. In the strategy the idea is to load three bottles with uniform colour and then move ink around for a number of moves until the bottles are mixed up. •Advantage: Result is always solvable since the bottles are created in a reversed-game strategy. •Disadvantage: It is hard to develop an algorithm which…arrow_forwardWrite a loop of your choice that continues to read an integer x as long as x not divisible by 5 and 3. Complete the missing code in the space provided below. { int x=1; ............ }arrow_forwardLottery.java, to generate a lottery of a two-digitnumber. The two digits in the number are distinct. (Hint: Generate the first digit.Use a loop to continuously generate the second digit until it is different from thefirst digit.)arrow_forward
- Develop a solution that will calculate the average temperature, given a set of temperatures. The number of temperatures may vary from time to time. (Use a trip value (counter) to stop the processing of the loop.) Test the solution with the following 10 temperatures78, 90, 85, 80, 87, 83, 75, 90, 86 and 70arrow_forwardPrint numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3arrow_forwardP1 P2 P3 P4 A pentagonal number is one that corresponds to dots arranged into a pentagon. Above are the first four pentagonal numbers and their pentagons. The pentagonal number PN has sides made of N dots. When you count the dots for a pentagonal number, include the dots for the inner pentagons. So to figure out how many dots PN has, find out how many P(N-1) has and add the dots for the new sides of size N. P1 = 1, P2 = 5, P3 = 12, P4 = 22 Figure out a recursive formula for PN and then write a function that implements it. That is, implement pentagonal() using recursion. pentagonal(1) -> 1 pentagonal(2) -> 5 pentagonal(3) -> 12arrow_forward
- PYTHON A perpetuity pays a coupon value of C each and every period forever. Given a discount rate of r, the value of a perpetuity is given by V=∑t=1∞C(1+r)t Compute the value of a perpetuity using the summation formula. In the function below, use a for loop to estimate the value of a perpetuity, approximated to N periods. def summation_formula(C,r,N):arrow_forward: In the classic problem FizzBuzz, you are told to print the numbers from 1 to n. However,when the number is divisible by 3, print "Fizz''. When it is divisible by 5, print "Buzz''. When it isdivisible by 3 and 5, print"FizzBuzz''. In this problem, you are asked to do this in a multithreaded way.Implement a multithreaded version of FizzBuzz with four threads. One thread checks for divisibilityof 3 and prints"Fizz''. Another thread is responsible for divisibility of 5 and prints"Buzz''. A third threadis responsible for divisibility of 3 and 5 and prints "FizzBuzz''. A fourth thread does the numbers.arrow_forwardOutput integer's digits Given an input positive integer, output each digit on its own line, starting with the rightmost digit. Ex: If the input is 935, the output is: 5 3 9 Hints: Use the mod operator (%) to get the rightmost digit. Mod by 10 to get the rightmost digit. Use a loop that keeps a current dividend (the number being divided). In each iteration, output the rightmost digit, then update the divisor by dividing by 10. End the loop when the divisor is 0. in javaarrow_forward
- 1. FizzBuzz 2.0 by CodeChum Admin Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game: • print "Fizz" if the number is divisible by 3 • print "Buzz" if the number is divisible by 5 • print "FizzBuzz" if the number is divisible by both 3 and 5 • print the number itself if none of the above conditions are met Input 1. An integer Output The first line will contain a message prompt to input the integer. The succeeding lines will contain either a string or an integer. Enter n: 15 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz main.c 9 10 11 12 =======2==***** 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include main int n; printf("Enter n: "); scanf("%d,&n"); int n1 = 0; } while (n-c-n1):{ if (n%30 && n%5--0); { printf("fizzbuzz"); } else if("%3--0"); { printf("fizz"); } else…arrow_forwardJavaarrow_forwardpython language.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education