被吊打的学渣
2018-02-03 15:06
Main:
package com.imooc; public class Main { public static void main(String[] args){ Book book = new Book(); book.input(); } }
BookInputError:
package com.imooc; class BookInputError extends Exception { BookInputError() { super(); } }
Book:
package com.imooc; import java.util.Scanner; public class Book { public void input () { String name; String number; Scanner scanner = new Scanner(System.in); name = scanner.nextLine(); number = scanner.nextLine(); try { for (int i = 0; i <= number.length()-1; i++) { if(number.charAt(i) < '0' && number.charAt(i) > '9') { throw new BookInputError(); } } } catch (BookInputError bookInputError) { System.out.println("input error"); } System.out.println(name+number); } }
输入实例:
8989 uuu
这个我觉得应该抛出异常,结果没有。
if(number.charAt(i) < '0' || number.charAt(i) > '9')
逻辑关系错了?这么简单的问题我都没看出来 :(
Java入门第三季
409792 学习 · 4340 问题
相似问题