Results 1 to 3 of 3
Thread: Accumulation Help
- 10-28-2010, 07:37 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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 07:40 PM.
- 10-28-2010, 08:21 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Try using a StringBuilder.
- 10-29-2010, 08:10 AM #3
Cross posted with the suggestion given here, but without acknowledging the help
How to Accumulate results - Java Programming Forums
db
Bookmarks