• 11-25-2012, 11:49 PM
sezzy
Hi All,

I have a code that I have been given, and I need to calculate manually - I know that the answer is 66, but I'm not exactly sure how they get to that answer.

Can someone please explain to me the x=b(a,b) equation? Because for the life of me the maths I'm doing doesn't add up to 66?

a=3
b=-3
x=10
• 11-25-2012, 11:56 PM
Fubarable
I'm not sure that this question can be answered given the data you've presented so far.
• 11-25-2012, 11:57 PM
sezzy
Sorry,

Code:

```public class Question4 {   public static int a(int b, int c) {       int x=0; x=c-b;       return x;   } public static int b(int c, int d) {       int x; if (c<d) {         x=a(c,d);       } else {         if (d<c) {             x=a(d,c);         } else {             x=0;         }       } return x;   } public static void main(String args[]) {       int a=3; int b=-3;       int x=10;       x=b(a,b); System.out.print(x); x=b(b,a); System.out.print(x);   } }```
I'm not allowed to calculate it using a computer, I must calculate manually...
• 11-26-2012, 12:30 AM
Fubarable
Your code's indentation is all over the place making it *very* hard to read and understand. For the benefit of others, here is your code re-formatted:

Code:

```public class Question4 {   public static int a(int b, int c) {       int x = 0;       x = c - b;       return x;   }   public static int b(int c, int d) {       int x;       if (c < d) {         x = a(c, d);       } else {         if (d < c) {             x = a(d, c);         } else {             x = 0;         }       }       return x;   }   public static void main(String args[]) {       int a = 3;       int b = -3;       int x = 10;       x = b(a, b);       System.out.print(x);       x = b(b, a);       System.out.print(x);   } }```
In the future, please format your code better when posting it here. You are asking volunteers to help you, and if we can't read your code, we can't understand it, and if we can't understand it, we can't help. Besides, since you're asking effort from us, it's only fair that you put in effort likewise.

OK, you need to walk through your code step-by-step to see why it returns 66. Have you done this yet? If so and you're still confused, which part confuses you?
• 11-26-2012, 12:37 AM
sezzy
Sorry, I'm very new to all this stuff.

I'm confused by the "," in the equation, so if a=3, b= -3 and x=10,

Then my equation looks like 10=-3(3,-3)...which should equal 6, but I'm not seeing 6...unless my maths is as bad as my java coding... :\
• 11-26-2012, 12:39 AM
Fubarable
Hint 1: the x = 10 part is just to throw you off. x is promptly given another value, that returned by the b method. So you can safely ignore that x was assigned 10 and assume that it was initially assigned nothing.
Hint 2: the b method and the b variable are *completely* unrelated. It's not -3(3, -3), but rather it's b(3, -3). Same for the a method and variable.
• 11-26-2012, 12:44 AM
sezzy
Oh! So that's asking the difference between one and the other? Wow, now I feel stupid...I was trying to figure out why it was 0 when it should have been 6...

Thank you so much, now I just need to learn to pay attention! :o:
• 11-26-2012, 01:12 AM
pbrockway2