× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
w
3
w
3
e
3
3
r
3
g
2
2
b
2
M
2
V
2
f
2
c
2
New Topic  
Stromile Stromile
wrote...
Posts: 299
Rep: 0 0
6 years ago
Which of the following methods would properly compute the value of x % y (x mod y) recursively, assuming that x and y are not negative numbers?
a.   public int recursiveMod(int x, int y)
{
   if (x < y) return y;
   else return recursiveMod(x, y - x);
}
b.   public int recursiveMod(int x, int y)
{
   if (x == y) return 0;
   else return recursiveMod(x - y, y) + 1;
}
c.   public int recursiveMod(int x, int y)
{
   if (x < y) return x;
   else return recursiveMod(x - y, y) + 1;
}
d.   public int recursiveMod(int x, int y)
{
   if (x < y) return x;
   else return recursiveMod(x - y, y);
}
e.   public int recursiveMod(int x, int y)
{
   while (x > y)
      x = x - y;
   return x;
}
Read 29 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
This site is awesome
wrote...

Yesterday
Thanks for your help!!
wrote...

2 hours ago
This calls for a celebration Person Raising Both Hands in Celebration
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1278 People Browsing
Related Images
  
 294
  
 832
  
 1029