zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    Redis(二)
    Redis
    Nginx
    Linux的环境配置
    深入mysql
    SpringBoot入门
    Thymeleaf入门
    Mybatis之resultMap
    Mybatis入门
    使用第三方实现微信登录
  • 原文地址:https://www.cnblogs.com/1-Admin/p/6086785.html
Copyright © 2011-2022 走看看