Hello all(adsbygoogle = window.adsbygoogle || []).push({});

If we want to write arecursive methodthat multiplies two positive integers using repeated additions, we know that: [tex] a\times b = a + (a\times(b-1)) [/tex] Would this be correct:

Code (Text):

// pre: a and b are positive

// post: returning the product of a and b.

public int mult(int a, int b )

a*b = a +(a * (b-1))

if( b ==1)

return(a);

else

return mult(a + a*(b-1)))

Also if you had:

How would you find the output when a 3 is passed? I got a bumch of hellos and goodbyes, but I got it wrongCode (Text):

public void hello(int n )

{

System.out.println("hello n = ",n);

if(n > 1)

hello(n-1);

System.out.println("goodbye n = ", n);

Thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Comp Sci Questions

**Physics Forums | Science Articles, Homework Help, Discussion**