我需要帮助将indexOf
字符串与字符串数组进行比较并显示正确的匹配项。
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”,我希望它比较字符串的第一个/第二个字符并从字符串数组中返回匹配项。