Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Good one..... ( System.out.println() )

 
Adeeshwar Singhal
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess the ans............

System.out.println(5+4+3*2+" equals "+5+4+3*2);
scroll down to see the ans.......
















15 equals 546
It is just for information... If anybody needs explanation, come and burn it with fire.............
Anyone interested in Overriding question see the Tricky one............. by me again.......
Adeesh
---------------------------------------------
It is chilling cold out here, Start burning ur wood ranchians.....
[This message has been edited by Adeeshwar Singhal (edited November 30, 2000).]
[This message has been edited by Adeeshwar Singhal (edited November 30, 2000).]
[This message has been edited by Adeeshwar Singhal (edited November 30, 2000).]
 
Jorma Koistinen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess the ans...
public class Have{
private Have(){
int x=1702845791;
int y=014537656537;
int a=0x657f5d5e;
int b=014537656540;
System.out.println(this.getClass().getName()+" "+Integer.
toHexString(x--<<(y-->>>(a++/x*x++^--a))/(b++>>>(y--/--a))).
toUpperCase());
}
public static void main(String[]_){
new Have();
}
}</code>
jorma
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think the first part of an overloaded + has to be a String
 
Amond Adams
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have CAFEBABE
 
Adeeshwar Singhal
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have some CAFE JORMA.
That was really good one....... Could u also throw some light on it by dissecting it a bit.
Hope to hear from u soon......
Adeesh
( Try the one on Overriding with subject as Tricy One...........)
-------------------------------------------
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't this one same as the old post??
Ajith
 
Jorma Koistinen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<body>
<pre>
Hi Adeeshwar !
I try to throw some light to this code.
The Operator precedence is the only thing to look at:
Operators listed from highest precedence to lowest:
</pre>
GroupOperators
postfix operators <code>[] . (params) expr++ expr--</code>
unary operators <code>++expr --expr +expr -expr ~ !</code>
creation or cast <code>new (type)expr</code>
multiplicative <code>* / %</code>
additive <code>+ -</code>
shift <code><< >> >>></code>
relational <code>< > >= <= instanceof</code> <tr><td>equality <td><code>== !=</code> <tr><td>bitwise AND <td><code>&</code> <tr><td>bitwise exclusive XOR <td><code>^</code> <tr><td>bitwise inclusive OR <td><code>|</code> <tr><td>logical AND <td><code>&&</code> <tr><td>logical OR <td><code>| |</code> <tr><td>conditional <td><code>?:</code> <tr><td>assignment <td><code>= += -= *= /= %= >>= <<= >>>= &= ^= |=</code>


<pre>
public class Have{
private Have(){
int x=1702845791; //Decimal = 0xcafebabe/2
int y=014537656537; //Octal = 0xcafebabe/2
int a=0x657f5d5e; //Hex = 0xcafebabe/2 -1
int b=014537656540; //Octal 0xcafebabe/2 +1
/*
System.out.println(this.getClass().getName()+" "+Integer.
toHexString(x--<<(y-->>>(a++/x*x++^--a))/(b++>>>(y--/--a))).
toUpperCase());
*/
//(x--<<(y-->>>(a++/x*x++^--a))/(b++>>>(y--/--a)))
//Splitting this Monster to smaller pieces in this order:

x--; //From left to right
y--;
int par1=(a++/x*x++^--a);//First parenthes to count
int par2=(y>>>par1); //Unsigned shift
b++;
int par3=(y--/--a);
int par4=(b>>>par3);
int par5=(par2/par4);//Integer division= 1
int par6=(x<<par5); >
//Overflow OOps !! ??
//I didn't ment that way x<<1 = x*2

System.out.println(this.getClass().getName()+" "+Integer.
toHexString(par6).toUpperCase());
}
public static void main(String[]_){
new Have();
}
}
I hope this helps
</pre></body></html>

[This message has been edited by Jorma Koistinen (edited December 01, 2000).]
[This message has been edited by Jorma Koistinen (edited December 01, 2000).]
[This message has been edited by Jorma Koistinen (edited December 01, 2000).]
 
Adeeshwar Singhal
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for such a wonderful explanation of operator precedence Jorma.
I understood ur explanation very well. But I couldn't get exactly why did it print CAFEBABE. Does this toHexString() do all the magic or there is something else.......
Adeesh
----------------------------------------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic