当程序运行时,当输入负数或字母时,catch 不会捕获错误。否则程序运行良好,其他任何事情都没有错误。当输入不正确的输入时,它只是捕获未捕获。 for (int customer=0; customer<numberOfCustomers; customer++) { try { // get amount used by customer as String, convert to double GBused = Double.valueOf(Accounts[customer][USED]); // compute bill based on the customer's plan selection switch (Accounts[customer][SELECTION]) { case "Plan-A": bill = computeBill (GBused, PLAN[A][LIMIT], PLAN[A][PRICE]); break; case "Plan-B": bill = computeBill (GBused, PLAN[B][LIMIT], PLAN[B][PRICE]); break; case "Plan-C": bill = computeBill (GBused, PLAN[C][LIMIT], PLAN[C][PRICE]); break; case "Plan-D": bill = computeBill (GBused, PLAN[D][LIMIT], PLAN[D][PRICE]); break; default: bill = 0.00; break; } // convert the bill to a String and save into the array Accounts[customer][BILL] = String.valueOf(bill); } // end of try catch (NumberFormatException e) { System.out.println ("Values for GB used must be numeric"); }
添加回答
举报
0/150
提交
取消