Honestly, I think this exercise is wrong. None of the answers are correct.

The answers that get closer to be right are both B and C. The exercise assumes that the oposite of x>y is y<x, which is wrong. The oposite of x>y is y<=x. So the equivalent to

is

Letter B would also be correct if it was like this:

There is no point confusing things by changing < to >=, you have to stick with what the question said. Not as if you had actually got the < and >= the right way round.

Originally posted by Campbell Ritchie: Jesper Young is correct.

There is no point confusing things by changing < to >=, you have to stick with what the question said. Not as if you had actually got the < and >= the right way round.

I don't agree. Jesper certainly is correct (!(x < y) is not the same as (y < x)). But there's no correct answer in the given list. > is always oposite to <= [ December 29, 2007: Message edited by: Roberto Perillo ]

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339

posted

0

Thanks to you all My personell view is Jesper Young is right.He has given a correct explanation.

I also think that B and C are the right answers. Look at if statement and what it tells us? Get max. Isn't it?

a) min b) z=x<y ?y :x is z=y>x ?y :x -it means get max c)the same as b d)min

A dreamer is one step behind the achiever, and the achiever was once a dreamer.

Dale Carnegie
Greenhorn

Joined: Oct 12, 2007
Posts: 9

posted

0

Another idea... with if x=y... in b we would get z=x not z=y like at if. But what is the difference... only if x and y are objects not primitives. But here we have > = operators... who knows may be x and y objects of Integer [ December 29, 2007: Message edited by: Dale Carnegie ]

Both options b and c are correct. Case 1: x!=y,x<y, x=4, y=5, then z=5, using both b and c. Case 2: x!=y, x>y, x=6,y=5, then z=6, using both b and c. Case 3: x=y, x=5,y=5, then z=5, using both b and c.

Dale Carnegie
Greenhorn

Joined: Oct 12, 2007
Posts: 9

posted

0

b is not correct because:

Integer a,b; a = 777; b = 777;

//(a == b) false // a.equals(b) true

So

z1=a; z2=b; //(z1 == z2) false

So z will have a reference to another object not like at the if statement.

Originally posted by Roberto Perillo: Honestly, I think this exercise is wrong. None of the answers are correct.

The answers that get closer to be right are both B and C. The exercise assumes that the oposite of x>y is y<x, which is wrong. The oposite of x>y is y<=x. ...

Sorry Roberto, you're wrong...

The exercise does not assume that x > y is the opposite of y < x. It assumes that x > y is the same asy < x, and that's correct. So answer (c) is correct.

The opposite of x > y is x <= y. Not x < y, so answer (b) is wrong.

Note that the syntax of the ? : construct is like this: expression ? value-if-true : value-if-false

So, an if-statement like

is equivalent to: z = x > y ? x : y; Roberto, you've got it the wrong way around in your answer above.

Instead of x > y you can write y < x (answer c).

If you're still doubting this, write a small test program to verify how it works. [ December 30, 2007: Message edited by: Jesper Young ]

Yes partners, I read and reread carefully the question. I got it the wrong way around, that's right, Jesper... sorry I read the question too quickly at the first time... the essence of this exercise is to know what is the same to x < y, not what is oposite to x < y... correct, x < y is the same as y > x... in this case, the only correct answer is indeed letter (C)... Thanks Jesper, you got everything cleared, man.

Good evening, everyone... and happy new year!!! [ December 30, 2007: Message edited by: Roberto Perillo ]