package com.baobaotao.ditype; import java.util.Iterator; import java.util.List; import java.util.Map; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static String reverse(String str,int start,int end) { char s[]=str.toCharArray(); while(start<=end) { char t=s[start]; s[start]=s[end]; s[end]=t; start++; end--; } str=new String(s); return str; } public static String reverseDomain(String str) { str=reverse(str,0,str.length()-1); int index[]=new int[10]; for(int i=0;i<index.length;i++) { index[i]=-1; } int j=-1; for(int i=0;i<str.length();i++) { char c=str.charAt(i); if(c==‘.‘) { j++; index[j]=i; } } index[++j]=str.length();//设置结束位置 int start=0; int end; for(int ind=0;ind<index.length&&index[ind]!=-1;ind++) { end=index[ind]-1; str=reverse(str,start,end); start=index[ind]+1; } return str; } public static void main(String[] args) { String str="www.baibaitao.comm"; str=reverseDomain(str); System.out.println(str); } }
时间: 2024-10-29 04:56:38