[問題] 新手發問

看板java作者 (/* I'm not worth */)時間15年前 (2010/07/28 23:55), 編輯推噓1(103)
留言4則, 4人參與, 最新討論串1/2 (看更多)
public class First { public static void main (String[] 參數) { int up, low; double result; String ans = "繼續"; String choice = "繼續"; while(ans == choice){ System.out.println("請輸入上底"); up = input.nextInt(); System.out.println("請輸入下底"); low = input.nextInt(); System.out.println("請輸入高"); result = (up + low) * input.nextInt() / 2; System.out.println("面積 = "+result); System.out.println("是否繼續?"); choice = input.nextLine(); //為啥這行執行時沒執行到就結束了? } } } 新手發問 最後一行 註解那邊 我是想要讓使用者決定要不要繼續下一次的執行 但是好像程式執行時沒執行到那行就結束了 請問是怎麼了 怎麼解決? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.237.127

07/29 00:23, , 1F
改成input.next();
07/29 00:23, 1F

07/29 00:36, , 2F
這樣的話不管我輸入甚麼都匯進入下一 次loop QQ
07/29 00:36, 2F

07/29 00:49, , 3F
clean build?
07/29 00:49, 3F

07/31 13:55, , 4F
關鍵就在版主說的那兩個地方 最後一行其實是有在執行的
07/31 13:55, 4F
文章代碼(AID): #1CK5BXwZ (java)
討論串 (同標題文章)
文章代碼(AID): #1CK5BXwZ (java)