File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Problem (9 & 5)

 
Pankaja Shinde
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this context, & is the bitwise and operator.

9 = 1001
5 = 0101

9 & 5 = 0001
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& 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
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic