Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Nicholas Barbosa

Greenhorn
+ Follow
since Jun 04, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nicholas Barbosa

Campbell Ritchie wrote:That is different from what Jeanne found. I don't have the book. Please post a scanned/photographed image of that page showing who you got 461.



Hi,

I used a quiz from Wiley Test Banks and I found the true answer, thanks for attention!

Jeanne Boyarsky wrote:

Campbell Ritchie wrote:So with no ordering 145 would count as the same output as 451?


Correct. The question asks which of the #s appear in the output



Yes, in my book, there is no option for 4 5 1, only for 4 6 1. This is the problem.

Paul Clapham wrote:Ah, sorry, I got it backwards, didn't I? Yes, it looks like you're correct.

yes!! Oh,ok
I'm 15 years old and I'm studying hard for the exam, you dont know how your answers ,makes me happy !! Thanks!!! I'm in the right way...oh yeeees!!

Paul Clapham wrote:When I compile it and run it, the output is 4 5 1. I leave it to you to explain why that is the case. (The line you're disagreeing with is equivalent to the notorious "b = b++", isn't it?)

By the way, the output from your revised version is 4 6 1.

The true answer is 4 5 1,cause b is post increment and not pre increment,but there s no option for answer 4 5 1 in the book.

Nicholas Barbosa wrote:In the practice exercises, in the question 9, the real answer should be 4 5 1, not 4 6 1.. Following the snippet :
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : b++));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

Answer: 4 5 1
Look, in the second line, b its post-increment, not pre increment to be 6, should be 5, but there are no answer for 5. If was this snippet:
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : ++b));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

The answer should be: 4 6 1.   But in the book, b its post increment,so the real answer is 4 5 1,but there's no option for this.

Correct?

In the practice exercises, in the question 9, the real answer should be 4 5 1, not 4 6 1.. Following the snippet :
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : b++));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

Answer: 4 5 1
Look, in the second line, b its post-increment, not pre increment to be 6, should be 5, but there are no answer for 5. If was this snippet:
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : ++b));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

The answer should be: 4 6 1.
But in the book, b its post increment,so the real answer is 4 5 1,but there's no option for this

Correct?
Im 15 years old and want to know if I paid attention to the explanations about unary operators and their precedence.

Little part of the table

1.Post increment (expression++/--)
2. Pré increment (++/--expression)

In the example(page 84 and 85) -> int lion; int tiger = ++lion * 5 / lion--;

The book explains that, first java works above pre increment and after post increment, but its not!

Should be something like -> First post increment and after pre increment, cause post increment has more precedence, or the order of the table is wrong, or in this case java start left to right?

Thanks!!!