練習題目
撰寫一個程式,連續要求使用者輸入資料,包括學生姓名與其成績,輸入完後使用者可以進一步輸入編號來找出對應的學生資料;如果使用者在輸入成績時輸入不是合法的數字字串,則程式必須可以印出錯誤訊息加以警告(提示:NumberFormatException)。程式範例
String input = new String();System.out.printf("請輸入學生成績:");
input = scanner.next();
int grade = Integer.parseInt(input);
if (grade < 0 && grade > 100) {
System.out.println("成績範圍須介於0~100之間");
沒有留言:
張貼留言