public class Demo {
static String usernames[] ={"张三李四","张三","李四"};
public static void main(String[] args) throws RegisterException {
Scanner sc=new Scanner(System.in);
System.out.println("请输入你的名字");
String username= sc.next();
check(username);
}
public static void check (String username) throws RegisterException {
for (int i=0;i< usernames.length;i++) {
if(username.equals(usernames)){
throw new RegisterException("该用户已经被注册");
}else {
System.out.println("成功");
}
}
}
}
为啥我的代码每次运行的时候都是成功啊,RegisterException是我自定义的异常,请吴彦祖,彭于晏帮忙看看,谢谢了!