看板 java 關於我們 聯絡資訊
我其實是這樣寫的 這是某桃園一帶某私立大學大一java程式設計作業~_~(泣~我的水準只能接這種外包) BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("請輸入你要的數字:"); String cin =new String(); while(true){ cin = buf.readLine(); try{ int test = Integer.parseInt(cin); break; } catch(NumberFormatException e) { System.out.println("這不是數字"); continue; //寫辛酸的 } } ※ 引述《appleboy46 (我是道明柏毅)》之銘言: : 推 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("執行成功"); : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.59.147.201
TonyQ:應該不會是我們系上得學弟妹外包的吧 XD 03/06 09:57
slalala:被發現了 03/06 10:33
slalala:你們學校寒假作業有夠多的 03/06 10:40
TonyQ:那群(...) 我早就把答案放在他們拿的到的地方了.... 03/06 10:55
TonyQ:那些寒假作業是從我大一之前就有的東西..幾年來都沒要求 03/06 10:57
TonyQ:算了 -_-;; 系上風氣不是我該/能去擔心跟關心的 03/06 11:00
slalala:這跟學校沒關係 程式設計的課大多這樣 不懂語法可以幹SA勒 03/06 11:16
linjack:淦... 那我資傳的畢製能不能外包啊 ......OTL 03/06 11:33
slalala:我打算創業 進駐大學院區 公司名稱"專題外包" 03/06 11:43