• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Program on operators

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit, the answer is here.
reply
    Bookmark Topic Watch Topic
  • New Topic