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
Which of the following characters is not allowed for java variable names
Rainbow [258]
The variables must begin with a letter of the alphabet, a dollar sign or a underscore. After the first character you may add numbers as well. All special characters besides the dollar sign and underscore and not allowed in variables.
8 0
4 years ago
What is a computer briage coures​
Stella [2.4K]

what's your choices for this question

4 0
3 years ago
Jason works for a restaurant that serves only organic, local produce. What
sergeinik [125]

Answer:

green buisness

Explanation:

8 0
3 years ago
Read 2 more answers
1.The hardware that allows data to be transmitted from a computer along a telephone line to another computer at the other end is
valkas [14]

So this is called a modem we use it to send  and receive info over telephone lines

Hope this helps

-scav

4 0
3 years ago
You have decided to remove a recently installed feature which method can you use to remove this feature
Aliun [14]
If it is on the desktop screen you just right click on the icon and select delete. from there if you're on a windows computer it goes to your recycle bin then you right click the recycle bin and a little rectangle pops up an in that rectangle it says clear recycle bin and once you press that all of the stuff that was in there is deleted. now if your on a computer that has chrome os installed you just go to the files screen and right click what you want to delete and click delete and it's gone. 
6 0
3 years ago
Other questions:
  • you want to discard your old computer ,want to securely erase that data from your hard drive. what can you use to do this and wh
    12·1 answer
  • What was the han dynasty and the roman empire known for?
    5·1 answer
  • Which of the following is NOT one of the most important elements when designing a website?
    8·2 answers
  • When a Firewall is a hardware interface, it is referred as a
    6·1 answer
  • What is a series of instructions or commands that a computer follows used to create software
    9·1 answer
  • The process of searching for a special pattern of symbols within a larger collection of information is called pattern ____.
    12·1 answer
  • 3. What are the first steps that you should take if you are unable to get onto the Internet? (1 point)
    15·1 answer
  • A cybersecurity analyst is currently investigating a server outage. The analyst has discovered the following value was entered f
    9·1 answer
  • All of the following are strategies to help you prepare for standardized test except <br>​
    5·1 answer
  • If we want to access files located in a directory on a remote server, which of these options would we use?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!