0
我需要從一個字符串與字符串數組比較的indexOf
幫助並顯示正確的匹配。的indexOf()String類的Java
public static void printvehicleMAKE(ServiceAppointment[] services, Scanner input){
System.out.print("Enter vehicle make: ");
String make = input.next();
String model = make.substring(0,3);
System.out.println(model);
boolean flag = false;
System.out.println("Details of all vehicles manufactured by " +make+" : ");
for (int i=0;i<6;i++) {
if(model.equalsIgnoreCase(services[i].getvehicleMAKEMODEL())){
System.out.printf("\n%10s%15s%20s", services[i].getregoNUMBER(),
services[i].getbuildYEAR(), services[i].getvehicleMAKEMODEL());
flag = true;
}
}
if(flag==false)
System.out.print("No service appointments were found for vehicles "
+ "made by " + make);
}
例子。如果我輸入「toyota」或「aston」,我希望它比較字符串的第1個/第2個字符,並返回字符串數組中的匹配項。
而你的實際問題是? – 2013-04-07 10:50:11
如果我輸入「到」,我希望它返回字符串/秒,在數組列表中的字符串的第2個字符相匹配。例如,如果我輸入「as」,它將顯示「aston martin」或「to」,它將顯示「豐田凱美瑞」等等。 我不知道的indexOf()方法是真正有用與否,當談到比較字符串。 – Ken 2013-04-07 11:03:13
現在,如果我輸入「到」,會顯示「沒有找到預約服務車輛」,而不是「豐田佳美」,或者說前兩個字符匹配其他字符串。 – Ken 2013-04-07 11:04:56