在我當前的程序中,有一種方法要求用戶輸入作爲String
輸入的產品說明。但是,當我稍後嘗試打印出此信息時,僅顯示String
的第一個字。這可能是什麼原因?我的方法如下:掃描儀只讀取第一個字而不是行
void setDescription(Product aProduct) {
Scanner input = new Scanner(System.in);
System.out.print("Describe the product: ");
String productDescription = input.next();
aProduct.description = productDescription;
}
因此,如果用戶輸入「桔子味汽水汽酒」,該System.out.print
只會產生「閃閃」。
任何幫助將不勝感激!
你打我8秒+1 –
太棒了。非常感謝!這工作:) – Kristian