如果用户必须只输入字符串,输入中不包含整数和符号,如何捕获整数?先生,请帮我做我的初学者报告。
import java.util.*;
public class NameOfStudent {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name = "";
System.out.print("Please enter your name: ");
name = input.nextLine(); // How to express error if the Strin contains
//integer or Symbol?...
name = name.toLowerCase();
switch(name)
{
case "cj": System.out.print("Hi CJ!");
break;
case "maria": System.out.print("Hi Maria!");
break;
}
}
}