由于错误,我的 Java 代码不是 运行ning,如何将其修复为 运行

My Java code is not running due to error, how do I fix it to run

我得到的错误是: 错误:找不到或无法加载 main class Main 原因:java.lang.ClassNotFoundException:主要

我是 Java 的新手,不明白在这种情况下该做什么或如何将此代码修复为 运行

由于错误描述,我认为这与classes有关,但我不确定

import java.util.Scanner;
import java.util.regex.*;

class Login{
    String user;
    String password;
    String firstName;
    String lastName;

    boolean checkUserName(String user){
        if(user.length()>5 || user.indexOf('_')==-1){
            return false;
        }
        else{
            return true;
        }
    }

    boolean checkPasswordComplexity(String password){
        String regex = "^(?=.*[0-9])"
                       + "(?=.*[a-z])(?=.*[A-Z])"
                       + "(?=.*[@#$%^&+=])"
                       + "(?=\S+$).{8,20}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(password);
        return m.matches();
    }

    boolean loginUser(String user,String password){
        if(user.equals(this.user) && password.equals(this.password)){
            return true;
        }
        else{
            return false;
        }
    }

    String returnLoginStatus(String user,String password){
        if(loginUser(user, password)){
            return "Welcome "+firstName+lastName+" it is greater to see you again.";
        }
        else{
            return "Username or passoword incorrect, please try again.";
        }
    }

    void registerUser(String firstName,String lastName,String user,String password){

        if(checkUserName(user)){
            this.user = user;
            System.out.println("Username successfully Captured");
        }
        else{
            System.out.println("Username is not correctly formatted, please ensure that your username contains an underscore and is no more than 5 characters long.");
        }
       if(checkPasswordComplexity(password)){
           this.password = password;
            System.out.println("Password successfully captured");
        }
        else{
            System.out.println("Password is not correctly formatted, please ensure that the passoword contains atleast 8 characters, a capital letter, a number and a special character.");
        }
        if(checkUserName(user) && checkPasswordComplexity(password)){
            this.firstName = firstName;
            this.lastName = lastName;
            System.out.println(returnLoginStatus(user, password));
        }
    }
}

class Registration{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        System.out.print("Enter the username:");
        String user = sc.nextLine();
        System.out.print("Enter the password:");
        String password = sc.nextLine();
        System.out.print("Enter your First Name:");
        String firstName = sc.nextLine();
        System.out.print("Enter Your Last Name:");
        String lastName = sc.nextLine();
        sc.close();
        Login user1 = new Login();
        user1.registerUser(firstName, lastName, user, password);

    }
   
    
}

每当在该网站上编译 Java 代码时,该网站的编译器都会查找名为“Main”的 class 以开始执行。一旦它的编译器发现 class,它就会调用具有 public static void main(String[] args) 签名的任何方法。在您的情况下,没有 class 名为“Main”的名称,因此编译器不知道从哪里开始 运行 程序。一个简单的解决方法是将 class 名称“Registration”更改为“Main”。