• 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

Came across this accidentally

 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohhhh, stupid me, Should have seen that one, Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic