Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: retrieve next character in alfabet

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default retrieve next character in alfabet

    Hi guys,

    New in Java so i have a lot of questions. Beginning with this one.

    I'm trying to retrieve the next character of a character. A->B, B->C, ...., Z->A
    using this code:

    import java.util.*;
    import java.text.*;
     
    public class Letter
    {
        private char letter;
     
        public Letter()
        {
            // initialise instance variables
            letter = 'A';
        }
     
        // Method
        public char getLetter()
        {
            return letter;
        }
     
        public char next(){
     
            int intChar;
     
            intChar = this.letter.charCodeAt();
     
        }
    }

    The idea is (example) to convert 'A' to ASCII code (65), increase it (66) and convert this to 'B'
    I know char is a primitive type, not an object. I tried several things with Character. No succes. What is going wrong.
    The compiler complains about .charCodeAt: char cannot be dereferenced
    Last edited by jps; April 16th, 2013 at 01:44 PM. Reason: fixed code tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: retrieve next character in alfabet

    char values and variables can be used in arithmetic operations directly: 'a' + 1 = 'b'
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    25
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: retrieve next character in alfabet

    Hi
    in the next function get the letter say
    char let = getLetter();
    let ++ ;

    This will give you the next alphabet.

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: retrieve next character in alfabet

    that's simple. Thanks

Similar Threads

  1. Retrieve value from JSF
    By WhiteSoup12 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 11th, 2012, 02:49 PM
  2. Retrieve data from other table
    By kichkich in forum JDBC & Databases
    Replies: 2
    Last Post: June 23rd, 2011, 07:51 AM
  3. Retrieve coordinates of other windows
    By Knox in forum AWT / Java Swing
    Replies: 1
    Last Post: April 10th, 2011, 02:03 PM
  4. [HELP] How can I retrieve attribute/method?
    By k4it0xtr3me in forum Object Oriented Programming
    Replies: 0
    Last Post: January 21st, 2011, 02:18 AM
  5. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM

Tags for this Thread