我写了一个功能,它自称的次数是应该的3倍。我在程序中调用了一次,但总共执行了4次。任何人都可以解释我的问题吗?
public static String[] MainBooker(Document doc, int counter){
System.out.println("test");
Queue<String> mainbooker = new LinkedList<String>();
Elements span = doc.select("td");
for(int i = counter+1 ; i < counter +21; i++){
String inf = span.eq(i).text();
if(counter%2 == 0 && i%2 == 0){
if(!inf.equals("")){
if(inf.contains("'"))
inf = inf.replaceAll("'", "\'");
mainbooker.add(inf);
}
}
else if(counter%2 != 0 && i%2 != 0){
if(!inf.equals("")){
if(inf.contains("'"))
inf = inf.replaceAll("'", "\'");
mainbooker.add(inf);
}
}
}
String[] mainbooker_info = new String[mainbooker.size()];
int i = 0;
for (String info : mainbooker) {
mainbooker_info[i] = info;
writeToFile(mainbooker_info[i]);
i++;
}
//Stack:
//M/V || firstname || middleName || lastName || DoB
// Zipcode+ number || street || country || phonenumber || email
return mainbooker_info;
}
我在if语句中调用它:
else if(inf.contains("Main booker") || inf.contains("Haupt-Bucher") || inf.contains("Hoofdboeker")){
String[] result = MainBooker(doc, i);
if(!result[2].equals("-")){
informationBasic.add(result[1] +" "+result[2]+ " "+ result[3]);
}
else if(result[2].equals("-")){
informationBasic.add(result[1] + " "+ result[3]);
}
mainbooker.addAll(Arrays.asList(MainBooker(doc, i)));
}
答案 0 :(得分:1)
在您的代码中,
else if(inf.contains("Main booker") || inf.contains("Haupt-Bucher") || inf.contains("Hoofdboeker")){
if(!MainBooker(doc, i)[2].equals("-")){
informationBasic.add(MainBooker(doc, i)[1] +" "+MainBooker(doc, i)[2]+ " "+ MainBooker(doc, i)[3]);
}
else if(MainBooker(doc, i)[2].equals("-")){
informationBasic.add(MainBooker(doc, i)[1] + " "+ MainBooker(doc, i)[3]);
}
mainbooker.addAll(Arrays.asList(MainBooker(doc, i)));
}
MainBooker已多次通话。试试这个:
else if(inf.contains("Main booker") || inf.contains("Haupt-Bucher") || inf.contains("Hoofdboeker")){
String[] result = MainBooker(doc, i);
if(!result[2].equals("-")){
informationBasic.add(result[1] +" "+result[2]+ " "+ result[3]);
}
else if(result[2].equals("-")){
informationBasic.add(result[1] + " "+ result[3]);
}
mainbooker.addAll(Arrays.asList(result));}