展开全部
按你个个规则应该是个死循环吧,
输入的字符第二位要是有数字就是死循环,不知道是e5a48de588b662616964757a686964616f31333335323434不是这样的,
例一例二都是这个结果
当出现9时,按规则2来替换,继续匹配,
2按规则用9替换,这样下来没有结果,不知我的理解是否正确,还是你的规则没有讲清楚呢
不知是你的规则有问题还是我的代码有问题,如果表中字符排列不当会死循环
public class BiaoTi {
//定义匹配表
static String[][] Biao = {
{ "a", "0", "j", "x", "e", "q", "j", "m", "f" },
{ "b", "9", "i", "y", "f", "2", "h", "f", "e" },
{ "c", "8", "h", "e", "g", "w", "g", "d", "d" },
{ "d", "7", "g", "a", "h", "s", "r", "s", "c" },
{ "e", "6", "f", "d", "b", "x", "3", "s", "b" },
{ "f", "5", "e", "h", "v", "x", "w", "f", "a" },
{ "g", "4", "d", "k", "n", "c", "e", "g", "9" },
{ "h", "3", "c", "y", "l", "v", "s", "a", "8" },
{ "i", "2", "b", "e", "j", "b", "f", "f", "7" },
{ "j", "1", "a", "q", "s", "n", "h", "d", "6" }
};
public static boolean isNum(String str) {
return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String str_Test = "395654545";//测试字符串
boolean flag;//是否重复匹配标志
do {
String str_Temp = "";
flag = true;
for (int i = 0; i < str_Test.length(); i++) {
String temp = str_Test.substring(i, 1 + i);
// System.out.println(temp);
if (isNum(temp)) {
temp = Biao[Integer.parseInt(temp) - 1][i];
flag = false;
}
str_Temp += temp;
}
str_Test = str_Temp;
System.out.println(str_Test);
} while (!flag);
System.out.println(str_Test);// 最络结果
}
}