废话不多说了,直接给大家贴代码了,具体代码如下所述::
软件包com.gdh.backtext; import java.util.hashmap; import java.util.map; import java.util.map.entry; public class class backText {字符串text {string text; public backText; public backText; super(super(super(); this.text = null;} public backText(string text){super(); this.text = text;} public boolean isbackText(){for(int i = 0,j = text.length() - i-1; i <= j; i ++,j - ){if(text.charat(i)!= text.charat(j)) }} return true;} public映射<字符,integer> countstring(){map <targue,integer> map = new hashmap <>(); int count = 0; 字符串temp = new String(); for(int i = 0; i <text.length(); i ++){if(temp.indexof(text.charat(i),0),0)<0){temp+= text.charat(i); }} map.clear(); for(int i = 0; i <temp.length(); i ++){if(!map.containskey(temp.charat(i))){for(int j = 0; j <text.length(); j ++){if(text.Charat.charat(charat(j)== temp.charat(i)) }} map.put(temp.charat(i),count); 计数= 0; }} //循环打印for(entry <字符,integer> item:map.entryset()){system.out.println(“字符:” + item.getKey() +“ +”值:“ + item.getValue()); }返回地图; } public string convert(){int checksum = 0; int itemcount = 0; map <carture,integer> map = countstring(); for(输入<字符,整数>项目:map.entryset()){checkSum+= item.getValue(); if(item.getValue()%2!= 0)itemcount ++; } if(itemCount> 1){system.out.println(“该字符串不能转换为回文字”); 返回null; } stringBuffer temp = new StringBuffer(text); //线程安全// StringBuilder temp = new StringBuilder(); //线程非安全int int begidx = 0; int endidx = checksum-1; 字符键= null; boolean flag = false; for(输入<字符,整数> item:map.entryset()){if(checkSum%2 == 0){for(int i = 0; i <item.getValue()/2; i ++){temp.set.setcharat(begidx ++++++++++egen.getKey(getKey()); temp.setcharat(endidx--,item.getKey()); }} else {if(item.getValue()%2 == 0){for(int i = 0; i <item.getValue()/2; i ++){temp.setCharat(begidx ++,item.getKey()); temp.setcharat(endidx--,item.getKey()); }} else {key = item.getKey(); flag = true; 继续; }}} if(flag){for(int i = 0; i <map.get(key); i ++){temp.setcharat(begidx ++,key); }} return temp.tostring();} public static void main(string [] args){backText bt = new backText(“ 1122223455667788990”); if(!bt.isbacktext())system.out.println(“该字符串不是回文字”); else system.out.println(“该字符串是回文字”); 字符串dest = new String(); system.out.println(“开始转换...”); dest = bt.convert(); system.out.print(“转换后的结果为:”); system.out.println(dest); }}}以上所述是小编给大家介绍的java版本的回文字算法(java版本),希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!,小编会及时回复大家的!