除了正则表达式,将字符串解析为int和try / catch块还有其他任何方法可以处理InputMismatchException&带扫描仪的NoSuchElementException?
import java.util.Scanner;
public class TestingScanner
{
public TestingScanner() {
tokenizeLine();
}
public void tokenizeLine() {
Scanner scanner = new Scanner("Paul 56 3125 Actor");
String name = scanner.next();
int age = scanner.nextInt();
int money = scanner.nextInt();
String occupation = scanner.next();
System.out.println(name);
System.out.println(age);
System.out.println(money);
System.out.println(occupation);
scanner.close();
}
}