• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program on operators

 
kanna kesavan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Geethakrishna Srihari
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21492
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit, the answer is here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic