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 3 of 3

Thread: How to Accumulate results

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to Accumulate results

    Hello I am very new to java and 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;
     
    // How to accumulate?
    text=Character.toString(character);
     
    }
     
    } 
    return text; 
    }

    any advice is appreciated! I have been suggested a String builder, but im not quite sure on how to use it, is there a simpler method?
    Last edited by helloworld922; October 29th, 2010 at 01:58 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: How to Accumulate results

    Cross posted after being advised to use a StringBuilder at
    Accumulation Help - Java Forums

    Didn't even have the courtesy to thank the member who made the suggestion.

    db

Similar Threads

  1. How to make this print only the first 200 results?
    By noFear in forum Java Theory & Questions
    Replies: 2
    Last Post: September 3rd, 2010, 03:29 AM
  2. How can i view search results by using servlet and jsp?
    By noFear in forum Java Theory & Questions
    Replies: 3
    Last Post: August 27th, 2010, 11:22 AM
  3. Showing database results
    By randyrr in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 27th, 2010, 11:26 PM
  4. How to print results to screen
    By NinjaLink in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2010, 01:46 PM
  5. Football Results
    By RSYR in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2009, 07:24 PM