1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sleet_krkn [62]
3 years ago
7

What is wrong with the following recursive sum method? The method is supposed to sum up the values between 1 and x (for instance

, sum(5) should be 5 + 4 + 3 + 2 + 1 = 15). public int sum(int x) { if (x == 0) return 0; else return sum(x – 1) + x; } Group of answer choices the base case should return 1 instead of 0 the recursive case should return sum(x – 1) + 1; instead of sum(x – 1) + x; the recursive case should return sum(x) + 1; the method should return a boolean instead of an int the base case condition should be (x <= 0) instead of (x = = 0)
Computers and Technology
1 answer:
Karo-lina-s [1.5K]3 years ago
8 0

Answer:

The base case condition should be (x <= 0) instead of (x = = 0)

Explanation:

The given recursive function works fine for positive number. However, it returns an error when the value passed to the function is negative.

To prevent this, the base case should be x <= 0.

This will allow the program returns 0 if a negative number or 0 is passed to the function.

Hence, the changes to be made is to replace the base case with x <= 0

You might be interested in
Can computers be opened from the All programs submenu
Bad White [126]

Answer:

I am pretty sure...if not try duck duck go

8 0
1 year ago
What is one example of an emerging class of software
morpeh [17]

Answer:

"Push" Model web browsers.

Explanation:

6 0
3 years ago
Please help.........​
natima [27]

Answer: For the first dot you can I want a playground in my community

Make homework easier I dont know foor the other two

Explanation:

6 0
3 years ago
To hide gridline when you display or print a worksheet
Bingel [31]
Hide it under the copier
7 0
4 years ago
The Consumer Price Index (CPI) is the tool used to measure inflation. It is calculated through a ____ which asks the amount of m
Scilla [17]
<span>A. Door-to-door survey.</span>
6 0
4 years ago
Other questions:
  • I need the alphabet quickly! sorry bad with remembering!
    10·1 answer
  • you want to search in your contacts in your email program. You enter the person's first name and last name in the search box. Yo
    8·1 answer
  • A standard science experiment is to drop a ball and see how high it bounces. Once the bounciness of the ball has been determined
    10·1 answer
  • You have configured a LAN with 25 workstations, three network printers, andtwo servers. The workstations and printers will have
    9·1 answer
  • Consider a Rational class designed to represent rational numbers as a pair of ints, along with methods reduce (to reduce the rat
    10·1 answer
  • Natalie is a secretary and must complete a large amount of filing this afternoon. At 1:00 PM, the office receptionist gets sick
    10·1 answer
  • Which of these personal protective equipment items prevents injury from falling objects ?
    15·1 answer
  • Which of the following is the correct financial function that returns the periodic payment for a loan?
    10·1 answer
  • Who is responsible for developing the physical background for the characters by creating buildings, landscapes, and interiors?
    14·1 answer
  • Which statement about broadcasting a slideshow online is true?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!