我仍然有一個問題,行String部分= input.nextLine();.它不斷崩潰,如果我刪除「線」,它是好的,但我想讀整個字符串包括空格和存儲它。假設我已經聲明瞭所有的變量和數組。String.nextLine()Java - 崩潰
System.out.print("Enter registration number of vehicle: ");
String inputREGO = input.nextLine();
System.out.print(inputREGO);
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.next();
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.");
public boolean addPARTDETAILS(String partDESCRIPTION, double partCOST){
if(partDESCRIPTION.isEmpty() || partCOST <= 0){
System.out.println("Invalid input, please try again!");
return false;
}
else{
StringBuffer strBuf = new StringBuffer();
strBuf.append(" ").append(partDESCRIPTION).append(" ($").append(partCOST).append(")");
partLIST += strBuf;
System.out.printf("\n%10s", partLIST);
System.out.println("\n Parts recorded successfully for vehicle " + getregoNUMBER());
totalPART+=partCOST;
return true;
}
}
什麼是輸入宣佈爲? – 2013-04-08 12:55:42
什麼類型有「輸入」? – dontcare 2013-04-08 12:56:23
請發佈堆棧跟蹤,顯示正在引發異常和在哪裏。我也建議你閱讀[FAQ](http://stackoverflow.com/faq)和這些[提示](http://tinyurl.com/so-hints)。 – 2013-04-08 12:56:25