File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes adding to letters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "adding to letters" Watch "adding to letters" New topic
Author

adding to letters

peter huff
Greenhorn

Joined: Nov 14, 2005
Posts: 14
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

Joined: Aug 31, 2004
Posts: 11343

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...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
In other words, Java works (mostly) the same way that C does in this regard.

Layne
[ January 29, 2006: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
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

Joined: Nov 14, 2005
Posts: 14
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding to letters
 
Similar Threads
Duplicate Characters
WA #1.....word association
Java Developer, opensource
Jakob Nielsen Declares the Letter "C" Unusable
What am I?