String Enterproducts=in.next();
for(int i=0;i<?;i++)
我想繼續輸入產品,直到它們完成。這裏應該是什麼?我們可以使用 .compareto()
方法嗎?如果是,那麼如何?如何滿足字符串條件?
String Enterproducts=in.next();
for(int i=0;i<?;i++)
我想繼續輸入產品,直到它們完成。這裏應該是什麼?我們可以使用 .compareto()
方法嗎?如果是,那麼如何?如何滿足字符串條件?
你應該使用,而像循環:
while (in.hasNext()) {
Enterproducts=in.next();
if (Enterproducts.equals ("end")) {
break;
}
//apply your business logic here what you want to do with entered string.
}
試試這個:
do {
Enterproducts = in.next();
} while (!Enterproducts.equalsIgnoreCase("end"));
或試試這個:
for (int i = 0; in.hasNext()&& !Enterproducts.equals ("quit"); i++) {
Enterproducts=in.next();
}
什麼是'in'在你的榜樣? – maksimov 2014-11-23 10:12:49
你是說你想要循環直到用戶想要停止輸入字符串值? – 2014-11-23 10:14:13