This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Program on operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Program on operators" Watch "Program on operators" New topic
Author

Program on operators

kanna kesavan
Greenhorn

Joined: May 09, 2005
Posts: 6
class Eg1 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((~x == -x - 1)+","+(~y == -y - 1));

byte x1 = 3, y1 = 5;
System.out.print((-x1 == ~x1 + 1)+","+(-y1 == ~y1 + 1));

}}


Please help me how to solve these type of questions if they appear in exam?
I need some manual steps to check my answer?
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
What is your current thinking on this question?, do you have a theory on why it generates the output you get when you compile and run it?
[ May 29, 2005: Message edited by: Marcus Green ]

SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
Originally posted by Marcus Green:
What is your current thinking on this question?, do you have a theory on why it generates the output you get when you compile and run it?

[ May 29, 2005: Message edited by: Marcus Green ]



not a relevent answer ...

kindly give relevent answer rancher ..

regards


Thanks and Regards, Amit Taneja
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I think it's very relevant. When people just ask questions without giving us any idea how much they understand already, then it seems like we are expected to explain everything, and there's an excellent chance that we'll be wasting time describing things that thee questioner knows already, or that they can't understand yet becuase they don't yet have sufficient background information. We're all unpaid volunteers here, and we don't exist simply to spew out answers to every question that people can think of. We're much more likely to be able to help if we have enough information that we can tell what level the questioner is at, and if we can see that the questioner is putting some effort into thinking and researching the answer.

I recommend JavaRanch's HowToAskQuestionsTheSmartWay and the page which inspired it, Eric Raymond's How to Ask Questions The Smart Way.


"I'm not back." - Bill Harding, Twister
Geethakrishna Srihari
Ranch Hand

Joined: May 25, 2005
Posts: 30
Keshav,
If you know whats two's complement you can get the catch of the question...

No need to apply any manual steps:

-x == ~x + 1 : true

~x inverts all the bits
add 1 to it...we get -x..
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
Originally posted by Jim Yingst:
I think it's very relevant. When people just ask questions without giving us any idea how much they understand already, then it seems like we are expected to explain everything, and there's an excellent chance that we'll be wasting time describing things that thee questioner knows already, or that they can't understand yet becuase they don't yet have sufficient background information. We're all unpaid volunteers here, and we don't exist simply to spew out answers to every question that people can think of. We're much more likely to be able to help if we have enough information that we can tell what level the questioner is at, and if we can see that the questioner is putting some effort into thinking and researching the answer.

I recommend JavaRanch's HowToAskQuestionsTheSmartWay and the page which inspired it, Eric Raymond's How to Ask Questions The Smart Way.



but the original question asked is obvious that he/she is not able to solve that particular expression which results to boolen
thats it...
i m not saying to give full explanation but here the thing are clearly mentioned...that she is asking ..how she get this answer..so the reply should be to present how ( by what method) the result is comming..
and not teaching the whole java book

don't mind sheriff..

regards
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Originally posted by amit taneja:

but the original question asked is obvious that he/she is not able to solve that particular expression which results to boolen
thats it...
i m not saying to give full explanation but here the thing are clearly mentioned...that she is asking ..how she get this answer..so the reply should be to present how ( by what method) the result is comming..
and not teaching the whole java book

don't mind sheriff..

regards


I totally agree with Jim in this regard. It is really frustrating when readers are expecting detailed answers, but is not even willing to spend a few minutes to qualified the questions. It is even more frustrating, after posting a detail answer, all you get is ... "not clear, try again".

But yes, the answer to this questions, relies on knowledge of the twos complement representation for negating numbers.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
why you moderator are continiously deleting my threads ???
i m unhappy

what if i write against it...can't you digest that ..i wrote truth in balanced way..


[ June 03, 2005: Message edited by: amit taneja ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Amit, the answer is here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program on operators
 
Similar Threads
drawing arrows
Slowly getting it
Calculating the distance between two points problem
Heelllpppp! I'm sooo lost
Please Help