廢話不多說了,直接給大家貼代碼了,具體代碼如下所述::
軟件包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版本),希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的! ,小編會及時回復大家的!