0
有人可以告訴我這有什麼問題嗎?我有一種感覺,j++
不能增加,因此離開j
在0,但我不知道。用戶名檢查錯誤
我在大約2分鐘內就使用了這個課程。它有什麼問題?這是我的代碼:
public static String[] names = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
//A to Z
public static String[] check = { "a","zz" };//Purposely errors a and z, runs the whole check to make sure it works
public static void usernameCheck() {
int errorCount = 0;
for(int i = 0; i < check.length;) {
for(int j = 0; j < names.length; j++) {
if(check[i].toLowerCase().equals(names[j].toLowerCase())) {
System.out.println("Username " + check[i] + " is already in use");
System.out.println(i + " and " + j);//Just a check if i or j is increasing at all
errorCount++;
}
if(j == names.length) {
System.out.println("Moving to next username");
j = 0;
i++;
}
}
}
if(errorCount > 0) {
System.out.println(errorCount + " Errors Occured");
System.out.println("Please consider revising usernames and try again.");
}else
System.out.println("Run Successful, no errors have occured.");
}
public static void main (String[] args) {
usernameCheck();
}
我的目的是保持0直到j完成長度,我已經增加了j完全讀取後重置爲0,因爲我想檢查每個名稱,然後移動到下一個檢查。 – Abszol