Java 对字符反转操作。

//把一段字符串反转后大小写互换位置
public class test_demo {
    public static void main(String[] args)throws Exception
    {
        //abCdCe-->ABcDcE
        System.out.println(strCast("abCdCe"));
        
    }
    public static String strCast(String s) throws Exception
    {
        if(!(s.matches("[a-zA-Z]+")))
            {
                throw new Exception("非纯字母");
            }
        
        char [] arr=s.toCharArray();
        for(int x=0;x<arr.length;x++)
        {
            if(arr[x]>='a'&& arr[x]<='z')
            {
                arr[x]=Character.toUpperCase(arr[x]);
            }
            else
            {
                arr[x]=Character.toLowerCase(arr[x]);
            }
        }
        for(int x=0,y=arr.length-1;x<y;x++,y--)
        {
            
            char temp=arr[x];
            arr[x]=arr[y];
            arr[y]=temp;
        }
        String str=new String(arr);
        
        return str;
    }
}
原文地址:https://www.cnblogs.com/1-Admin/p/6086785.html