This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Associate Certification (OCAJP 7) and the fly likes bitwsie and + - swap - explain the output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "bitwsie and + - swap - explain the output" Watch "bitwsie and + - swap - explain the output" New topic
Author

bitwsie and + - swap - explain the output

Kalpesh Soni
Ranch Hand

Joined: Jan 02, 2001
Posts: 312
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Please UseCodeTags next time you post a code snippet


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Which of the outputs you don't understand?

Let's start with swapPlus-method and add some more debugging info:


The output is as follows:
i[2147483646] j[2]
i[-2147483648] j[2]
i[-2147483648] j[2147483646]
i[2] j[2147483646]

Kalpesh Soni
Ranch Hand

Joined: Jan 02, 2001
Posts: 312
I was reading some article and someone said A | B, A ^ B, A ^ B swaps variables without tempraroay 3rd var

but it doesnt, you have to use 3 XORs
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Kalpesh Soni wrote:I was reading some article and someone said A | B, A ^ B, A ^ B swaps variables without tempraroay 3rd var

Indeed variables aren't swapped, but maybe that's a typo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bitwsie and + - swap - explain the output
 
Similar Threads
Increasing Array Size
Basic Round Up question
Doubt Reg: initializing Variables with method call
array manipulation
please explain why the compiler is not complaining and why the output is 0