我想知道为什么为什么输入的遍历数组里面if语句中是true为什么却还是不抛出异常?
static String[] usernames = {"张三","李四","王五"};
public static void main(String[] args) throws RegisterException {
//使用Scanner输入注册信息
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要注册的用户名:");
String username = sc.next();
checkName(username);
}
//判断
public static void checkName(String username) throws RegisterException {
//遍历数组
for (String name :usernames){
if (username.equals(usernames)){
throw new RegisterException("错误");
}
}
System.out.println("注册成功");
}
数组中已经存在张三,都是输入张三却还是显示注册成功,不应该抛出异常后中断处理吗?