The following method attempts to return the median (middle) of three integer values, but it contains logic
Question:
The following method attempts to return the median (middle) of three integer values, but it contains logic errors. In what cases does the method return an incorrect result? How can the code be fixed?
Transcribed Image Text:
public static int medianof3 (int n1, int n2, int n3) { if (nl < n2) { if (n2 < n3) { return n2; } else { return n3; } else { if (nl < n3) { return n1; } else { return n3;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 57% (7 reviews)
The medianOf3 code fails when n3 is the smallest of the three numbers for example when the par...View the full answer
Answered By
Branice Buyengo Ajevi
I have been teaching for the last 5 years which has strengthened my interaction with students of different level.
4.30+
1+ Reviews
10+ Question Solved
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted:
Students also viewed these Computer science questions
-
How can program code be reused?
-
An approximate median can be found for data that have been grouped into a frequency distribution. First it is necessary to find the median class. This is the class that contains the median value....
-
What does it mean for a tax code to be convex? If a countrys corporate tax rate is flat, does it make sense for a firm to hedge?
-
Nu-Look Design, Inc., operated as a residential home improvement company. During calendar years 1996, 1997, and 1998, Ronald A. Stark not only was Nu-Looks sole shareholder and president but also...
-
A steam power plant with a power output of 150 MW consumes coal at a rate of 60 tons/h. If the heating value of the coal is 30,000 kJ/kg, determine the overall efficiency of this plant.
-
Write a program to test an integer value to determine if it is odd or even. As always, make sure your output is clear and complete. In other words, dont just output yes or no. Your output should...
-
Distinguish between shaft work and other kinds of work associated with a flowing fluid.
-
Ike issues $ 180,000 of 11%, three- year bonds dated January 1, 2013, that pay interest semiannually on June 30 and December 31. They are issued at $ 184,566. Their market rate is 10% at the issue...
-
Choose a company whose business is some what. It can be a company that you have worked for, have dealt with, or are just interested in. Identify a business process in this company that can benefit...
-
Electronic Heaven, Inc., sells electronic merchandise, including a personal computer offered for the first time in September, which retails for $695. Sales of this personal computer for the next...
-
Write a method called hasAnOddDigit that returns whether a given positive integer has at least one digit whose value is odd. Return true if the number has at least one odd digit and false if none of...
-
Consider a method getGrade that accepts an integer representing a students grade percentage in a course and returns that students numerical course grade. The grade can be between 0.0 (failing) and...
-
A 2.5 cm sphere is maintained at 50?C in an air stream or a water stream, both at 20?C and 2 m/s velocity. Compare the rate of heat transfer and the drag on the sphere for both fluids.GIVENA sphere...
-
Liquid nitrogen loaded into an insulated tank at 1 atm absolute pressure is kept at the boiling point by allowing a small amount of it to gradually evaporate and flow out of the tank. In order to...
-
A liquid A is heated from 20C to 60C flowing on the tube side of a shell and tube heat exchanger at a flow rate of 44 kg/s. Another liquid B flowing on the shell side is cooled from 100C to a...
-
Under certain conditions, evaporation of a solvent A from freshly-applied paint into air is controlled by diffusion. Assume that diffusion occurs through a thin film of stagnant air adjacent to the...
-
A large amount of a heavy oil has been accidentally spilled on a large, elevated parking lot and settled, coating all surfaces, including both flat areas and sloping access ramps. Following the...
-
An impurity is to be removed from an aqueous solution by adsorption on a selective adsorbent in a batch system. The solution, at 25C and containing 0.1 kg/m3 of the impurity, will be loaded into a 1...
-
Determine the equivalent capacitance between A and B for the group of capacitors in the drawing. 5.0 F 24 F 6.0 F 8.0F
-
1. Which of the four major types of information systems do you think is the most valuable to an organization? 2. How do you critically associate the ideas of business agility and business efficiency...
-
Consider a diagram of a telephone network, which is a graph G whose vertices represent switching centers, and whose edges represent communication lines joining pairs of centers. Edges are marked by...
-
Let G be a graph with n vertices and m edges such that all the edge weights in G are integers in the range [1,n]. Give an algorithm for finding a minimum spanning tree for G in O(mlog n) time.
-
Consider the following greedy strategy for finding a shortest path from vertex start to vertex goal in a given connected graph. 1: Initialize path to start. 2: Initialize set visited to {start}. 3:...
-
Which line of the following author reading segment would causes issues? 1: bookArr[i].authors = calloc(bookArr[i].numAuthors, sizeof(author_t)); 2: for (j=0; j < bookArr[i].numAuthors; j++) { 3: 4:...
-
3. (20 points) Consider three periodic tasks A, B and C with their respective periods as 4ms, 6ms and 8ms. The execution time required for each task is 1 ms. (a) Draw a figure/table to execute these...
-
Write a method (pseudocode) to reverse the queue using another empty queue. You may only use queue operations such as enqueue(), dequeue(), and size(). No other data structure can be used other than...
Study smarter with the SolutionInn App