高手入,求一循环判断的解决办法
ID UP
14 12
15 14
20 15
16 15
30 16
31 16
35 16
judge( "14 ", "35 "),例如,依据ID14得到UP=14的ID15,再依据UP=15的ID20得到UP=20的空记录,和UP=15的ID16得到ID30,ID31,ID35。查到35后judge()返回true,反之则是false。该怎么写循环判断,求高手解答,急需!!
------解决方案-------------------- private static boolean judge(String ID,String UP){
String[][] test = new String[][]{
{ "14 ", "15 ", "20 ", "16 ", "30 ", "31 ", "35 "},
{ "12 ", "14 ", "15 ", "15 ", "16 ", "16 ", "16 "}
};
if(ID.equals(UP))return true;
for(int i=0;i <test[1].length;i++){
if(test[1][i].equals(ID)){
String check = test[0][i];
if(check.equals(UP))return true;
boolean rtn = judge(check,UP);
if(rtn)return true;
}
}
return false;
}