看板 java 關於我們 聯絡資訊
slalala:這 很正常啊 因為你這個變數是在while內宣告 03/05 00:57
slalala:我會用Integer.parseInt(String str) 用Try catch去寫這題 03/05 00:59
您推的是這種嗎? BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); try{ System.out.print("請輸入你要的數字:"); int test = Integer.parseInt(buf.readLine()); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(e.toString() + "陣列程式發生錯誤"); } catch(ArithmeticException e) { System.out.println(e.toString() + "數學發生錯誤"); } catch(Exception e) { System.out.println(e.toString() + "程式發生錯誤"); } finally { System.out.println("執行成功"); } -- ******************************************************** * Appleboy Blog * * http://blog.Wu-Boy.com/ * * Appleboy Album * * http://pic.wu-boy.com * ******************************************************** -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.107.41
kyoby:真要用,還是把exception寫細,直接寫個大類上去不合适... 03/05 19:04
※ 編輯: appleboy46 來自: 140.123.107.41 (03/05 21:02)
appleboy46:樓上您說的是我改過的這樣嗎? 03/05 21:02
kyoby:那個parseInt是會拋NumberFormatException,而不是那啥數學 03/05 22:13