抱歉,我的头衔可能有些混乱。我对Java有点陌生,我正在尝试编写一些东西,以便在eclipse中运行代码时,控制台会要求您提供电子邮件地址,您输入该电子邮件地址后,email1将从以下位置更改:

String email1 = "";

至:

String email1 = "personsemail@mail.com";

有人可以告诉我该怎么做吗?

这是我的完整代码:

public class MainClass {

    public MainClass() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String email1 = "testemail1";
        String email2 = "testemail1";
        boolean isMatch;

        isMatch = email1.equals (email2);
        if (isMatch == true){
            System.out.println("Emails Match!");
        } else{
            System.out.println("Emails Dont Match");
        }
    }
}

最佳答案

使用Scanner#nextLine()方法从控制台读取一行文本。

// System.in represents input stream
Scanner scanner = new Scanner(System.in);

// print() not println()
System.out.print("Enter your email: ");

// Store email
String email1 = scanner.nextLine();

// close when done!
scanner.close();

07-27 21:09