import java.util.Scanner;
class RegisterException extends RuntimeException {
public RegisterException() {
super();
}
public RegisterException(String message) {
super(message);
}
}
class InputName {
String[] str = {"张三","李四","王五"};
String name;
public InputName() {}
public InputName(String name) {
this.name = name;
}
public void CheckName() {
for(String name: str) {
if(name.equals(this.name)) {
throw new RegisterException("亲,该用户名已经被注册");
}
}
System.out.println("恭喜您!注册成功");
System.out.println("您的用户名是:" + this.name);
}
}
public class Chapter1003 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要注册的用户名:");
String Username = sc.next();
InputName inputName = new InputName(Username);
inputName.CheckName();
}
}