• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding to letters

 
peter huff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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 ]
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • 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
  • 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???
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic