Shift character in Alphabet

char, java

Solution

It is because next chars after 'z' is punctuation chars and so on. You can shift so that 'z' will be 'n' for example.

toEncode[i] = (toEncode[i] + 13 - (int)'a') % 26 + (int)'a';

Problem

Possible Duplicate: ROT-13 function in java? I have to shift all char from a string 13 places in the alphabet ``` private static String encode(String line) { char[] toEncode = line.toCharArray(); for (int i = 0; i < toEncode.length; i++) { if (Character.isLetter(toEncode[i])) { toEncode[i] += 13; } } line = String.valueOf(toEncode); return line; } ``` The Problem is that for example 'z' get to a ?. How can I solve that? Thx for help.

Original source

Related problems