What is wrong with the following code, which attempts to add all numbers from 1 to a
Question:
What is wrong with the following code, which attempts to add all numbers from 1 to a given maximum? Describe how to fix the code.
Transcribed Image Text:
public static int sumTo (int n) { for (int i = 1; i <= n; i++) { int sum = 0; sum += i; return sum;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 77% (9 reviews)
The problem with the given sumTo method i...View the full answer
Answered By
Nazrin Ziad
I am a post graduate in Zoology with specialization in Entomology.I also have a Bachelor degree in Education.I posess more than 10 years of teaching as well as tutoring experience.I have done a project on histopathological analysis on alcohol treated liver of Albino Mice.
I can deal with every field under Biology from basic to advanced level.I can also guide you for your project works related to biological subjects other than tutoring.You can also seek my help for cracking competitive exams with biology as one of the subjects.
3.30+
2+ 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
-
What is wrong with the following "proof" that every matrix with at least two rows is row equivalent to a matrix with a zero row? Perform R2 + R1 and R1 + R2. Now rows 1 and 2 are identical. Now...
-
What is wrong with the following electron configurations for atoms in their ground states? (a) 1s22s23s1, (b) [Ne] 2s2 2p3, (c) [Ne] 3s2 3d5
-
What is wrong with the following calculation? (Guido Ubaldus thought that this proved the existence of God because something has been created out of nothing.) 0 = 0 +0 + 0 +.. - (1 - 1) + (1 1) + (1...
-
Julio sold his corporation to a competitor, Exeter LLC, for $100,000,000. Julio incorporated his business 17 years ago by investing $500,000 plus his proprietary know-how. There have been no other...
-
A heat pump is absorbing heat from the cold outdoors at 5C and supplying heat to a house at 25C at a rate of 18,000 kJ/h. If the power consumed by the heat pump is 1.9 kW, the coefficient of...
-
Its moving day, and you need to push a 100 kg box up a 20 ramp into the truck. The coefficients of friction for the box on the ramp are s = 0.90 and k = 0.60. Your largest pushing force is 1000 N....
-
Thrust vector control is a technique that can be used to greatly improve the maneuverability of military fighter aircraft. It consists of using a set of vanes in the exit of a jet engine to deflect...
-
Identify in what ledger (general or subsidiary) each of the following accounts is shown. 1. Rent Expense 2. Accounts ReceivableChar 3. Notes Payable 4. Accounts PayableThebeau
-
Project: Parole: Are We Better Off Without It? As you learned in this lesson, federal parole was eliminated in 1984. This made a dramatic impact on the incarceration system in the United States....
-
Total Cost Method of Product Pricing Smart Stream Inc. uses the total cost method of applying the cost-plus approach to product pricing. The costs of producing and selling 8,500 units of cell phones...
-
Write a method called printPalindrome that accepts a Scanner for the console as a parameter, prompts the user to enter one or more words, and prints whether the entered String is a palindrome (i.e.,...
-
Write a method called getGrade that accepts an integer representing a students grade in a course and returns that students numerical course grade. The grade can be between 0.0 (failing) and 4.0...
-
If the holding-period return on a money market mutual fund for the most recent seven days is 0.081%, what current (simple) yield and effective annualized yield will be quoted for the fund in the...
-
Creating a professional brand is critical to your job search. If you were to begin a job search today, what would your brand message be? What changes to your email address, signature block, voice...
-
Assume that you will be participating in a group interview in which several applicants for an internship program will meet with the companys recruiting team. You dont know what questions will be...
-
When applicants do not adequately prepare for standard interview questions, they often provide ineffective answers to inquiries about their weaknesses. Why is it a bad idea simply to admit a weakness...
-
Explain what a swap rate is. What is the relationship between swap rates and par yields?
-
What are the formulas for \(u\) and \(d\) in terms of volatility?
-
A 1.40- resistor is connected across a 9.00-V battery. The voltage between the terminals of the battery is observed to be only 8.30 V. Find the internal resistance of the battery.
-
If someone's Z-score for a variable was 0.67. Their score is a significant extreme score. Their score is not significant. O Their score is slightly above average. O Their score is an outlier.
-
If the outermost while loop of our implementation of quickSortInPlace (line 9 of Code Fragment 12.6) were changed to use condition left < right, instead of condition left /** Sort the subarray S[a.b]...
-
Suppose the method quickSortInPlace is executed on a sequence with duplicate elements. Prove that the algorithm still correctly sorts the input sequence. What happens in the partition step when there...
-
Consider a modification of the deterministic version of the quick-sort algorithm where we choose the element at index n/2 as our pivot. Describe the kind of sequence that would cause this version of...
-
Ned needs to produce more of his two products in order to increase his net income and has found a way to increase the limited resource, machine hours. He has two products, hammers and screwdrivers.....
-
What effect does an antagonist drug have over the receptors ?
-
Read this article on the differences and Comparisons between UNIX and LINUX http://www.diffen.com/difference/Linux_vs_Unix, then do some research and post your thoughts on each of the systems. Based...
Study smarter with the SolutionInn App