Forums Register Login

what will be the ans

+Pie Number of slices to send: Send
pulic class Integers{
public static void main(String[] args){
System.out.println(0*10+10+010);
}
}
what will be the ans, i think 20, is it right.
+Pie Number of slices to send: Send
This is rather easy to test by compiling and running it, no?
+Pie Number of slices to send: Send
i have no java compiler so please give me the answer...
+Pie Number of slices to send: Send
We don't do your homework for you here, but I will give you a hint: read this.
+Pie Number of slices to send: Send
The answer will of course be 22.

I'll leave it to you to work out how to get it to print 22!
+Pie Number of slices to send: Send
i got 18 ... leading zero interpreted as numeric literal ... 010 is eight in octal.
[ April 10, 2008: Message edited by: f. nikita thomas ]
+Pie Number of slices to send: Send
Let him work out the answer for himself . . .

And it really did print out 22 when I tried it.
+Pie Number of slices to send: Send
I also get it as "18" only, which seems to be obvious here!
+Pie Number of slices to send: Send
And I got 22.

Work it out
+Pie Number of slices to send: Send
Campbell, what are we missing out here? It looks like a puzzle wherein you are asked to just get a different answer by just changing one line or operator etc? -- so as to get 22!

here, it is very simple -- it has 3 operands [0*10+10+010] in which the the result of multiplication yields 0 and the rest two gives you 10 and 8 (010 in octal yielding 8 in decimal). The sum is 18!

How and why you get a different answer?
+Pie Number of slices to send: Send
 

How and why you get a different answer?



He didn't get a different answer. The answers are the same. Keep in mind that he didn't say what the exact output was, just what the result value was.

Now admittingly, Campbell, when something has to be explained, it isn't funny....

Henry
+Pie Number of slices to send: Send
That's correct Henry. But Campbell's posts were not saying anything about the formatting of output leaving room to think on other sides/aspects of it.

As it is you run the program, it gives 18 only. It is what my concern here! That's what i asked what is being missed out, if at all?
+Pie Number of slices to send: Send
BIG hint: what is 2*8 + 2*1?
+Pie Number of slices to send: Send
When you run as it is with the default priority of operators, it is 18. But how it helps in the OP's question.?
+Pie Number of slices to send: Send
I did run it with default priority. Henry and Fred know what I did, but I shall keep quiet for a little.
+Pie Number of slices to send: Send
Oh, all right then. I printed it with the %o tag in printf.
+Pie Number of slices to send: Send
Campbell that is fine

But we were talking about running the program without modifying and of course as it was.

But isn't it cheating?
+Pie Number of slices to send: Send
All right, it was cheating. Sorry.

But, has Shirsa Ray Chaudhuri worked out why it is 18 or 22 and not 20?

There were three terms to the arithmetic:
  • 0 * 10, which comes to 0.
  • 10, which is one more than nine and one less than eleven.
  • and 010 which is one more than seven and one less than nine.
  • 0 + 10 + 8 is 18.
  • Beginners are reminded that any integer literal beginning with 0 is in octal, so 010 is 10 in octal or 8 in decimal.
    Any integer literal beginning with 0x is in hexadecimal, so 0x10 is 16 in decimal.

    When I had the 18 decimal, the %o tag made it print in octal, so I got the printout of 22.
    +Pie Number of slices to send: Send
    this all are wrong cause opptions are 1)28,2)30,3)34,4)36,5)101010
    +Pie Number of slices to send: Send
     

    Originally posted by shirsa ray chaudhuri:
    opptions are


    If this is a question from book or mock exam, then please QuoteYourSources.
    +Pie Number of slices to send: Send
    The options are wrong, since the answer really is 18.
    +Pie Number of slices to send: Send
     

    Originally posted by shirsa ray chaudhuri:
    this all are wrong

    No, the results people have posted, with or without cheating, are all correct. You can get 12 as an output too, by using the %x tag to print in hexadecimal. If the answers are to be picked from a multiple choice list of 28 30 34 36 and 101010, you must have made a mistake when you copied the original question.
    +Pie Number of slices to send: Send
    Have you mistaken 0x10 for 0 multiplied by 10 (0*10)? If you were supposed to write 0x10, that would give one of the answers you listed. And as you have been asked, please post where you got the question from.
    +Pie Number of slices to send: Send
    good eye Campbell
    +Pie Number of slices to send: Send
     

    Originally posted by Campbell Ritchie:


    When I had the 18 decimal, the %o tag made it print in octal, so I got the printout of 22.



    Campbell, not intended to beat around the bush! My intention and puzzling all was about the "%o" tag which you used by yourself! and that caused the confusion!
    +Pie Number of slices to send: Send
     

    Originally posted by Campbell Ritchie:
    No, the results people have posted, with or without cheating, are all correct. You can get 12 as an output too, by using the %x tag to print in hexadecimal. If the answers are to be picked from a multiple choice list of 28 30 34 36 and 101010, you must have made a mistake when you copied the original question.



    That's true. As Ulf suggested, you should have better Quoted your source, which would have avoided the confusions as Campbell pointed out -- misinterpreting the 0X as * (multiplication).
    +Pie Number of slices to send: Send
    . . . and if I'm right, I can still get the result to print as 22!

    Raghavan, sorry for confusing people, but I challenge you to work out how to get the result of 22 on screen.
    +Pie Number of slices to send: Send
    Campbell, that's perfectly agreed. If you see my very first post i told that it looked like a puzzle wherein you are expected to bring a change in the output by just altering a single value or operator etc., -- Here it was achieved by changing the output formatter!

    That's okay but people should get clarified rather than getting confused -- Right?
    [ April 11, 2008: Message edited by: Raghavan Muthu ]
    +Pie Number of slices to send: Send
    the answer is 36
    +Pie Number of slices to send: Send
     

    Originally posted by shirsa ray chaudhuri:
    the answer is 36

    Really? That doesn't look right to me. Please quote the question exactly as written, and tell us where you got it from.
    money grubbing section goes here:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1189 times.
    Similar Threads
    operators
    output of this code
    Overloading wih static methods
    Snippet
    Quession on if(){} and so on
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 29, 2024 01:38:57.