//把一段字符串反转后大小写互换位置
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;
    }
}

 

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2021-05-17
  • 2022-02-27
  • 2021-12-03
  • 2021-12-14
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-02-27
  • 2021-04-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案