Carolin Sha

Ranch Hand

Posts: 68

1

posted 1 year ago

hi,

I am trying to understand and get the answer to the following program below from a java class I am doing.

with method f using n=3 into n+1 which is 3+1=4

f=4 so method f is 4 which is passed into method g

it gets confusing here, not sure what method g prints out (f(n)+f(n-1)) , 4+ (4-1) = 4 + 3

which is 7

is the output 7 not sure if this is correct, any help would be appreciated.

thanks

I am trying to understand and get the answer to the following program below from a java class I am doing.

with method f using n=3 into n+1 which is 3+1=4

f=4 so method f is 4 which is passed into method g

it gets confusing here, not sure what method g prints out (f(n)+f(n-1)) , 4+ (4-1) = 4 + 3

which is 7

is the output 7 not sure if this is correct, any help would be appreciated.

thanks

posted 1 year ago

Here, it should be

(f(n)+f(n-1))

= f(4) + f(3)

= (4+1)+(3+1) = 9

it gets confusing here, not sure what method g prints out (f(n)+f(n-1)) , 4+ (4-1) = 4 + 3

which is 7

Here, it should be

(f(n)+f(n-1))

= f(4) + f(3)

= (4+1)+(3+1) = 9

OCA, Java SE 8

posted 1 year ago

I think Omkar's explained it, but you could do yourself a lot of help by spacing things out, for example:

and

and improving the indentation so that braces ({}) line up.

I understand that the questions you get may not be

HIH

Winston

Carolin Sha wrote:it gets confusing here, not sure what method g prints out...

I think Omkar's explained it, but you could do yourself a lot of help by spacing things out, for example:

`g( f(3) );`

and

`System.out.println( f(n) + f(n-1) );`

and improving the indentation so that braces ({}) line up.

I understand that the questions you get may not be

*written*that way - this is often done deliberately to confuse you - but if need be copy it out for yourself on paper with the proper spacing and indentation.

HIH

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here