运行结果及报错内容,如何解决?怎么让在最后两个在转回呢

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

img

img


public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        for(int i=0;i<s.length();i++){
            int c=s.charAt(i)+3;
            //这里加一层判断,用if也可以
            //大写字符A到Z的ASCII代码分别是065到090
            //小写字符a到z的ASCII代码分别是097到122
            //因为这里是 +3 的结果,所以int 值就是 88+3  89+3  90+3    120+3  121+3  122+3
            //也可以把他放在  int c=s.charAt(i)+3; 上面,case 的值就是  88    89  90   120   121   122
            switch(c){
                case 91:
                case 92:
                case 93:
                case 123:
                case 124:
                case 125:
                    c-=26;
            }
            char ch=(char)c;
            System.out.print(ch);
        }
    }

把说明文字放到注释里了


 Scanner sc=new Scanner(System.in);
        String str =sc.nextLine();
        char[] chars = str.toCharArray();
        int max = (int) 'Z' , min = (int) 'A';
        for (int i = 0; i < chars.length; i++) {
            int i1 = chars[i] + 3;
            if(i1 <= max){
                chars[i] = (char)i1;
            }else{
                chars[i] = (char)(i1 - max - 1 + min);
            }
        }
        System.out.println(new String(chars));