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...
-
Londo Corporation (a calendar-year taxpayer) purchased a new car at a cost of $70,000 for use in its business in 2019. Compute the depreciation deductions for this car for 2019 and 2020.
-
What are the types of internal recruiting?
-
Vice Oil received the following selected information from its pension plan trustee concerning the operation of the companys defined-benefit pension plan for the year ended December 31, 2014. The...
-
Consider the following combinational circuit with 3 inputs a, b, c and two outputs F1 and Fo given by its truth table. a b C Fo F 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 0 1 1 0 0 1 1...
-
The following transactions affecting materials occurred in February: Feb. 1 Balance on hand, 1,200 ft @ $2.76, $3,312.00 (plastic tubing, materials ledger account #906). 5 Issued 60 ft to production...
-
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...
-
Which of the following alternatives would NOT be an acceptable way to write the sentence? F. NO CHANGE G. Demanding, my H. Demanding. My J. Demanding; my
-
A firm sells three products. Product 1 : $ 6 1 sales price per unit; $ 4 4 variable cost per unit. Product 2 : $ 2 2 sales price per unit; $ 1 2 variable cost per unit. Product 3 : $ 1 0 7 sales...
-
What is Photosynthesis?
-
Based on the following information for the year ended December 31, 2018, what is Earnings Per Share (in dollars and cents)? Retained Earnings $ 340,000 January 1, 2018 Cost of Goods Sold $ 620,000...
-
On January 1, 2015, Y. Knott Inc. issued $100,000 in bonds payable with an interest coupon of 10%. Since the market rate of interest was close to 12%, Y. Knott had to issue the bonds at 94 (that is,...
-
Jerald earned net income of $1,200,000 in 2024. There are 950,000 shares of common stock outstanding the entire year. The preferred shareholders received a $80,000 cash dividend. Compute Jerald's...
-
A 5-year annuity of ten $7,000 semiannual payments will begin 8 years from now, with the first payment coming 8.5 years from now. If the discount rate is 10 percent compounded monthly, what is the...
-
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...
-
The first video I have for your discussion is "Shock and Awe:The Story of Electricity" Part 1 is called "Spark"It runs from 0:00 to about 58 min, on the following link....
-
Find the present value of a 1 0 - year annuity of $ 8 0 0 0 per annum, given the interest rate of 6 % for the first year, 7 % for the second year, 8 % for the third year, 9 % for the fourth year, and...
-
The management accounting team of XYZ plc also came up with some questions and requested you to explain/answer them for the upcoming board meeting: 1. A chain of XYZ plc, BHealthy Ltd is a wholesale...
Study smarter with the SolutionInn App