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;

Printable View

- 04-29-2007, 06:30 PMLegolandWhat 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 PMlevent
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 PMderrickD
I changed the code float b = to this because it did not compile:

Code:`float b = (x+15) / (y-6) * x/ (y*2) /3;`

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 PMLegolandThanks both
I will continue to work on this tomorrow

- 08-13-2008, 07:58 AMEranga
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.