-1
我一直在試圖調試此代碼,但似乎無法弄清楚爲什麼即使條件已滿足(例如findTitle.equals(title));它仍然移動到'其他'條件。一切看起來很簡單,看起來是正確的。對此有何見解?'if'語句的問題
private void addNewMs() {
// TODO Auto-generated method stub
String title = Helper.readString("Enter movie title > ");
String theatre = Helper.readString("Enter theatre name > ");
Theatre Art = null;
for (int i = 0; i < movies.size(); i++){
String findTitle = movies.get(i).getTitle();
if (findTitle.equals(title)){
for (int a = 0; a < theatres.size();a++){
String findTheatre = theatres.get(a).getName();
if (findTheatre.equals(theatre)){
Art = theatres.get(a);
Movie m = movies.get(i);
int year = Helper.readInt("Enter year > ");
int month = Helper.readInt("Enter month > ");
int day = Helper.readInt("Enter day > ");
int hours = Helper.readInt("Enter hour > ");
int mins = Helper.readInt("Enter mins > ");
Date d = Helper.thisDate(year, month, day, hours, mins);
MovieScreening newScreening = new MovieScreening(d, m, Art, 0);
screenings.add(newScreening);
System.out.println("Added Successfully.");
}
else {
System.out.println("Movie and/or Theatre not found.");
break;
}
}
} else {
System.out.println("Movie and/or Theatre not found.");
break;
}
}
}
打印出'findTheatre'和'theatre'的值。 –
http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html - 將你的代碼拆分成更小的塊和方法,我敢打賭你發現了這個問題。 –
給了我們和你輸入的例子 – kai