很抱歉,我的标题可能有点令人困惑。我对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");
}
}
}
答案 0 :(得分:2)
使用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();