新方法不起作用

use*_*501 -3 java methods function

我收到了一个错误

"非法表达和错误的开始';' 预期"

我不知道我是否正在使用新方法,所以请帮助我,我需要这个用于学校工作.

public class Testing{
    public static void main(String args[])throws IOException{

    String un, pw, login;
    final String Username = "javajava";
    final String Password = "testing";

    BufferedReader inpt = new BufferedReader (new InputStreamReader(System.in));

    public void Login(){
    System.out.println("Please enter your Username & Password for you to be able to use the program");
    System.out.println("Warning! Case Sensitive!");

        for(int trial=3; trial>=1; trial--){
            System.out.print("Username: ");
            un = inpt.readLine();

            System.out.print("Password: ");
            pw = inpt.readLine();

            System.out.println();
            if(un.equals(Username) && pw.equals(Password)){
                System.out.println("User has successfully logged in!");
                break;
            } else {
                System.out.println("Sorry, you've entered an incorrect Username/Password - (" + (trial-1) + ") retries left");
            }
            if  (trial==1){
                System.out.println("It seems that you've reached the limit for the login attempts, please try again later");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*oun 6

你不能[1]在方法中有一个方法.

移动

public void Login(){

到外面

public static void main(String args[])throws IOException{.

我建议你阅读教程定义方法.


[1]您可以间接地拥有"方法内部的方法".可以有一个包含内部类的方法,该类将包含一个方法.所以..你实际上在方法中得到了一个方法;)