Exception in thread "main" java.lang.Error: Unresolved compilation problems:
i cannot be resolved to a variable
i cannot be resolved to a variable
i cannot be resolved to a variable
i cannot be resolved to a variable
at CheckPassword.PasswordValidator(CheckPassword.java:21)
at CheckPassword.main(CheckPassword.java:56)
Вот мой код: [code]import java.io.*; import java.util.*;
public class CheckPassword { public static void PasswordValidator(String password) { int n = password.length(); boolean hasDigit = false, specialChar = false, hasLetter = false; Set set = new HashSet(Arrays.asList('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+')); for (char i : password.toCharArray()) { if (Character.isLetter(i)) hasLetter = true; if (Character.isDigit(i)) hasDigit = true; if (set.contains(i)) specialChar = true; } int onlydigit = 0; int onlyletter = 0; if (n >= 1) { for (i = 0; i < n; i++) { char x = password.charAt(i); if (Character.isDigit(x)) { onlydigit++; } if (Character.isLetter(x)) { onlyletter++; } } } System.out.print("Your password " + '"' + password + '"' + " is "); if (n < 8) { if (n == onlydigit) { System.out.println("very weak"); } else { System.out.println("weak"); } } else { if ((hasDigit == true) && (hasLetter == true)) { if ((onlydigit + onlyletter) == n) { System.out.println("strong"); } else { if (specialChar == true) { System.out.println("very strong"); } }
} } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("ENTER YOUR PASSWORD: "); String password = sc.nextLine(); PasswordValidator(password); } } [/code] Код Visual Studio выдает следующую ошибку: [code]Exception in thread "main" java.lang.Error: Unresolved compilation problems: i cannot be resolved to a variable i cannot be resolved to a variable i cannot be resolved to a variable i cannot be resolved to a variable at CheckPassword.PasswordValidator(CheckPassword.java:21) at CheckPassword.main(CheckPassword.java:56) [/code] Как избежать этой ошибки?