在这道题中存在三种情况:

情况一:没有任何小写字母,即全部都是大写

情况二:存在小写字母,但只有一个且在字符串首位

情况三:除首位外还存在小写字母

那么我们可以定义一个变量max(小写字母在字符串中最远的下标索引)初始值设为-1(即代表不存在小写字母)

综上:当max == -1(字符串全部小写)

当max == 0(首字母大写,其他小写)

当max > 0(返回原字符串)

import java.util.*;
import java.io.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String orin = br.readLine();
        int max = -1;
        for(int i = 0;i<orin.length();i++){
            char a = orin.charAt(i);
            if(Character.isLowerCase(a)){
                max= i;
            }
        }
        // 首位小,其他为大
        if(max == 0){
            StringBuilder sb = new StringBuilder();
            String shou = (String.valueOf(orin.charAt(0))).toUpperCase();
            String wei = orin.substring(1,orin.length()).toLowerCase();
            sb.append(shou).append(wei);
            System.out.println(sb);
        }else if(max == -1){
            // 全为大
            System.out.println(orin.toLowerCase());
        }else{
            System.out.println(orin);
        }
    }
}