public class CaesarChiffre extends MiniJava { public static void main(String[] args) { // (a) String text = readString("Zu verschlüsselnder Text:"); // (b) int shift = read("Zyklischen Shift eingeben:"); shift = shift % 26; // bringe in (-26, 26) if (shift < 0) shift += 26; // bringe in [0, 26) // (c) String newText = ""; for (int pos = 0; pos < text.length(); ++pos) { char c = text.charAt(pos); // (d) if (c >= 'a' && c <= 'z') { newText += (char) ('a' + ((c - 'a') + shift) % 26); } else if (c >= 'A' && c <= 'Z') { newText += (char) ('A' + ((c - 'A') + shift) % 26); } else { newText += c; // keine Änderung } } // (e) write(newText); } }