This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Came across this accidentally

 
Vineeth Menon
Ranch Hand
Posts: 71
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I was creating a small program to create some random letters, and I came across this actually through a typo, but was interested how it actually happened



AS you can see this is a simple code where random characters are being generated. Instead of typing System.out.print(a+","), I typed System.out.print(a+',') and I got the output as a long list of numbers. Could anyone tell me how the numbers got generated?

PS: I did not get an error, I got the output as a large list of number.

Thanks in Advance.
 
Mack Wilmot
Ranch Hand
Posts: 88
Linux Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are adding 2 chars which gets cast to an int. You are seeing the int value of a letter added to the int value for a comma. So 'b' + ',' = 98 + 44 = 142
 
Vineeth Menon
Ranch Hand
Posts: 71
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhhh, stupid me, Should have seen that one, Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic