× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
w
3
w
3
e
3
3
r
3
b
2
M
2
V
2
f
2
c
2
c
2
K
2
New Topic  
Stromile Stromile
wrote...
Posts: 299
Rep: 0 0
6 years ago
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;
   }
a.   The base case should return 1 instead of 0.
b.   The recursive case should return sum(x - 1) + 1 instead ofsum(x - 1) + x.
c.   The base case condition should be (x <= 0) instead of (x == 0).
d.   The recursive case should return sum(x) + 1.
e.   The method should return a boolean instead of an int.
Read 60 times
1 Reply
Replies
Answer verified by a subject expert
se7ense7en
wrote...
Posts: 327
Rep: 0 0
6 years ago
Sign in or Sign up in seconds to unlock everything for free
1

Related Topics

Stromile Author
wrote...

6 years ago
Just got PERFECT on my quiz
wrote...

Yesterday
This helped my grade so much Perfect
wrote...

2 hours ago
Smart ... Thanks!
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  563 People Browsing
Related Images
  
 599
  
 4213
  
 454
Your Opinion
Do you believe in global warming?
Votes: 488

Previous poll results: What's your favorite math subject?