does a method used in main method need its own class? : im writing a code that checks password entries, my main method checks my secondary method and outputs a line depending on whether its true or false. my problem is when i compile it gives expected class error for my second method, but if i try to use the same class as my main it gives duplicate class error. i didnt think i needed a second class, anyone care to help me out?

    import java.util.Scanner;
    
    public class CheckPassword {
    public static void main(String[] args) {
    scanner input = new Scanner(System.in);
    System.out.println("Enter a password");
    password = input.nextLine();
    if (check(password)) {
       System.out.println("Valid Password");
       }
    else{
       System.out.println("Invalid Password");
       }
     }
    }
    
    public class CheckPassword {
    public static boolean check(String password) {
    boolean check = true;
    if(password.length() < 8) {
    check = false;
    }
    int num = 0;
    for(int x = 0; i < password.length(); i++) {
        if(isLetter(password.charAt(x)) || isDigit(password.charAt(x))){
            if(isDigit(password.charAt(x))){
                 num++;
           if (num >=2){
               check = true;    
           } 
           else{
               check = false;
            }
           }
          }
        }
      }  
    }