aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Simple Problem (9 & 5) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Simple Problem (9 & 5)" Watch "Simple Problem (9 & 5)" New topic
Author

Simple Problem (9 & 5)

Pankaja Shinde
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
class SimpleClass
{
public static void main(String[] args)
{
System.out.println("Hello World!" + (9 & 5));
}
}

Will this class compile ?
Explain.
What is the value of (9 & 5) ? How to calculate ?

Pankaj Shinde
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
In this context, & is the bitwise and operator.

9 = 1001
5 = 0101

9 & 5 = 0001
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
& operator is used as a binary operator in this case.
Hence the & operation will be done as shown above by Keith
and since the result is 1, the output should be

HelloWorld!1
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Pankaja,

In addition to the other good feedback you've gotten here, remember that bit manipulations like this one are a part of the 1.4 exam, but if you're studying for the 5.0 exam (which I'd recommend), you don't need to study any form of bit manipulation.

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Problem (9 & 5)