# Thread: What value will a and b have??

1. Member
Join Date
Apr 2007
Location
Sweden
Posts
12
Rep Power
0

## What value will a and b have??

Hi!
I´m completley stuck on this don´t know where to begin???
What value will a have and b after the below lines has been executed?

float x = 1, y = 2;
float a = x + 15 / y - 6*x/y*2/3;
float b = (x+15) / (y-6)) * x/ (y*2) /3;

2. levent Guest
You have mistyped the expression for b there. There is a missing left parenthesis or extra right parenthesis there.

And this is mostly operator precedence. Where are you stuck?

3. Member
Join Date
Apr 2007
Location
USA
Posts
50
Rep Power
0
I changed the code float b = to this because it did not compile:
Java Code:
`float b = (x+15) / (y-6) * x/ (y*2) /3;`
Once I did that then this line:
System.out.println("B= "+ b +" A = "+a);
gave this out put:
B= -0.33333334 A = 6.5
If you are looking for a certain output maybe you need to put () around what you want to calculate first.
What output are you expecting?

4. Member
Join Date
Apr 2007
Location
Sweden
Posts
12
Rep Power
0

## Thanks both

I will continue to work on this tomorrow

5. First of all, it's better to read about operator precedences. levent already gave a link. Did you read it? Then exactly tell us what you are expecting? Depends on that, what you are looking to do, have to use parenthesis in correct order.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•