我得到的String.charAt(INT)的調試錯誤行:不適用於行
ch = Ach.charAt(0);
Switch語句 - 的charAt
char ch;
String Ach;
Scanner input = new Scanner(System.in);
printvehicleMAKE(services, input);
do{
System.out.println("\n Service Item Recording Feature");
System.out.println(" ------------------------------");
System.out.println("\n\n A - Record Part Details");
System.out.println("\n B - Add Labour Hours");
System.out.println("\n X - Exit service item recording feature");
System.out.print("\n\nEnter your selection: ");
Ach = input.nextLine().toUpperCase();
ch = Ach.charAt(0);
switch(ch){
case 'A':
System.out.print("Enter registration number of vehicle: ");
String inputREGO = input.nextLine();
boolean flag = false;
for(int i=0; i<6; i++){
if(inputREGO.equalsIgnoreCase(services[i].getregoNUMBER())){
System.out.print("Enter Part Description: ");
String parts = input.nextLine();
System.out.print("Enter Part Cost: ");
Double cost = input.nextDouble();
services[i].addPARTDETAILS(parts, cost);
flag = true;
}
}
if(!flag)
System.out.println("No registration number were found in the system.");
break;
case 'B' :
break;
case 'X' :
System.out.println("Exiting system......");
break;
default: System.out.println("Error - invalid selection entered!");
break;
}
}while(ch!='X');
public static void printvehicleMAKE(ServiceAppointment[] services, Scanner
input){
System.out.print("Enter vehicle make: ");
String make = input.nextLine();
boolean flag = false;
for (int i=0;i<6;i++){
if (services[i].getvehicleMAKEMODEL().indexOf(make) != -1){
System.out.printf("\n%-10s%-8s%10s", services[i].getregoNUMBER(),
services[i].getbuildYEAR(), services[i].getvehicleMAKEMODEL());
flag=true;
}
}if(!flag)
System.out.println("No service appointments were found for vehicles "
+ "made by " + make);
}
問題是......? – 2013-04-08 16:01:55
錯誤是...? – 2013-04-08 16:02:38
請發佈錯誤消息 - 複製粘貼。並確保包含相關的線路標識。 – 2013-04-08 16:02:40