# What value will a and b have??

• 04-29-2007, 06:30 PM
Legoland
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;
• 04-29-2007, 08:02 PM
levent
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?
• 04-29-2007, 08:13 PM
derrickD
I changed the code float b = to this because it did not compile:
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?
• 04-29-2007, 09:28 PM
Legoland
Thanks both
I will continue to work on this tomorrow
• 08-13-2008, 07:58 AM
Eranga
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.