Results 1 to 3 of 3
  1. #1
    DreamNaut is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default Accumulation Help

    Hello I am writing a method that shifts each letter in a String over in the alphabet n times. I am having trouble figuring out a way to accumulate the results

    Code:
    public String shift(int n){

    char character;

    for (int i = 0; i < text.length(); i++)
    {
    character = text.charAt(i);
    if(character>='A'&& character<='Z'){
    character = (char) (character + n);
    if (character>'Z')
    character-=26;

    // ACCUMULATION HERE
    text=Character.toString(character);

    }

    }
    return text;
    }


    any advice is appreciated!
    Last edited by DreamNaut; 10-28-2010 at 06:40 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Try using a StringBuilder.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •