• 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

adding to letters

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, in C you can add a number to a letter and it will change the letter, ie A+1=B (not exactly cos you have to take into account asci). How would I go about doing the same thing in java?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know C, but from what you've posted, it sounds like it's basically the same, since a primitive char is fundamentally a numeric value that you can perform arithmetic on. Just note that a literal char needs to be enclosed by single quotes...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words, Java works (mostly) the same way that C does in this regard.

Layne
[ January 29, 2006: Message edited by: Layne Lund ]
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are running Java or C in a USS subsystem under zOS, with the system using the EBCDIC character set, you are not always going to get what you expect with code like this. Same with OS400.

Guy
 
peter huff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.... dont really understand that. I was under impression most systems used asci, i mean ebcidic is english and therefore i didnt think in common use as asci was more standardised???
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter, yes, most systems use ASCII to encode characters. What Guy was trying to tell you is that not all systems use ASCII. There are some operating systems that use EBCDIC, for example. There might be other systems that use other encodings.

So adding 1 to a character does not give you the same result on all systems. The result depends on the character encoding that the system uses.
 
Maybe he went home and went to bed. And took this tiny ad with him:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic