【发布时间】:2011-12-18 07:13:14
【问题描述】:
在我当前的程序中,一种方法要求用户输入产品描述作为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 只会产生“Sparkling”。
任何帮助将不胜感激!
【问题讨论】:
标签: java string java.util.scanner