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?