Consider the following Java method, which is written incorrectly: Under what cases will the method print the
Question:
Consider the following Java method, which is written incorrectly:
Under what cases will the method print the correct answer, and when will it print an incorrect answer? What should be changed to fix the code? Can you think of a way to write the code correctly without any if/else statements?
Transcribed Image Text:
// This method should return how many of its three // arguments are odd numbers. public static void printNumodd (int ni, int n2, int n3) { int count = 0; if (nl % 2 != 0) { count++; } else if (n2 % 2 != 0) { count++; } else if (n3 % 2 != 0) { count++; System.out.println (count + " of the 3 numbers are odd.");
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (9 reviews)
The code fails when more than one number is odd because it uses else if rather than if The t...View the full answer
Answered By
Ann Wangechi
hey, there, paying attention to detail is one of my strong points, i do my very best combined with passion. i enjoy researching since the net is one of my favorite places to be and to learn. i am a proficient and versatile blog, article academic and research writing i possess excellent English writing skills, great proof-reading. i am a good communicator and always provide feedback in real time. i'm experienced in the writing field, competent in computing, essays, accounting and research work and also as a Database and Systems Administrator
4.90+
151+ Reviews
291+ 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
-
Can you think of a marketing research technique that could not be supported online? Explain your answer.
-
Can you think of any circumstances under which an open-loop protocol, (e.g., a Hamming code) might be preferable to the feedback-type protocols discussed throughout this chapter?
-
Can you think of any reasons why not-for-profit firms would benefit less from doing strategic planning than for-profit companies?
-
Michael Mayfield, the president of Mendo Mill and Lumber Co., in California, received a notice of a legal claim from Edward Starski. The claim alleged that a stack of lumber had fallen on a customer...
-
Steam enters an adiabatic turbine at 10 MPa and 500oC and leaves at 10 kPa with a quality of 90 percent. Neglecting the changes in kinetic and potential energies, determine the mass flow rate...
-
Top managers of Alaska Flooring are alarmed by their operating losses. They are considering dropping the laminate flooring product line. Company accountants have prepared the following analysis to...
-
Find the probability of randomly selecting an adult from the sample who prefers an action movie or a horror movie.
-
Consider the following note payable transactions of Creative Video Productions. 2012 May 1 Purchased equipment costing $17,000 by issuing a one-year, 6% note payable. Dec 31 Accrued interest on the...
-
A company will pay a dividend of $10 per share today. This dividend is expected to grow at 12% per year for five years. Afterwards, no dividend will be paid for the next 3 years. After that period, a...
-
1. Besides reducing the risk of overpaying or underpaying suppliers, what are some other benefits AA would derive from its should be model? 2. Can you think of other domains besides air...
-
One of the exercises in Chapter 3 asked you to write a method that would find the roots of a quadratic equation of the form ax 2 + bx + c = 0. The quadratic method was passed a , b , and c and then...
-
Describe a problem with the following code: Scanner console = new Scanner (System.in); System.out.print ("What is your favorite color?"); String name = console.next (); if (name == "blue") {...
-
Compute the costs of the following sources of financing for Doosan Babcock: a. A \($1,000\) par value bond with a market price of \($985\) and a coupon interest rate of 12 percent. Flotation costs...
-
The following table contains the monthly operating costs of a company. Salary is not included. Determine the variance and standard deviation of the costs. Enero Febrero Marzo Abril Mayo Junio Julio...
-
Becker & Smith, CPAs, performs a financial statement review for BAM Markets ( BAM ) . Caroline, the manager on the job, learns that Don, a member of the review team, violated the independence rules....
-
Presented here are selected transactions for Sheridan Inc. during August of the current year. Sheridan uses a perpetual inventory system. It estimates a return rate of 10%, based on past experience....
-
. Complete both parts (a) and (b) below. ). In1 (a) Let X11, X12, ..., X be a random sample of size n from a population with mean and variance . Let X21, X22,..., X2n2 be a random sample of size n...
-
41. Let S be the cone z = x + y, z 2, oriented with outward unit normal. Use Stokes' theorem to evaluate the flux integral for the vector field SJ (V x F). ndS F(x, y, z) = (x y)i + 2zj + xk. -
-
In Problems, simplify each expression so that only positive exponents remain. y -3/2 . y -1
-
Compile data on consumption and expenditures for the following categories in 30 different countries: (1) food and beverages, (2) clothing and footwear, (3) housing and home operations, (4) household...
-
An ISBN-13 code, a new version of ISBN-10, is another example of a weighted checksum with 13 digits, in which there are 12 decimal digits defining the book and the last digit is the checksum digit....
-
One of the examples of a weighted checksum is the ISBN-10 code we see printed on the back cover of some books. In ISBN-10, there are 9 decimal digits that define the country, the publisher, and the...
-
Manually simulate the Adler algorithm (Figure 10.19) to calculate the checksum of the following words: (FBFF) 16 and (EFAA) 16 . Also show that the result is a weighted checksum. Figure 10.19 Start...
-
Sociology
-
I am unsure how to answer question e as there are two variable changes. In each of the following, you are given two options with selected parameters. In each case, assume the risk-free rate is 6% and...
-
On January 1, Interworks paid a contractor to construct a new cell tower at a cost of $850,000. The tower had an estimated useful life of ten years and a salvage value of $100,000. Interworks...
Study smarter with the SolutionInn App