File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Came across this accidentally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Came across this accidentally" Watch "Came across this accidentally" New topic

Came across this accidentally

Vineeth Menon
Ranch Hand

Joined: Aug 08, 2011
Posts: 71

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

Joined: Jul 27, 2011
Posts: 88

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

Joined: Aug 08, 2011
Posts: 71

Ohhhh, stupid me, Should have seen that one, Thanks
I agree. Here's the link:
subject: Came across this accidentally
It's not a secret anymore!