抱歉,我的标题可能有点令人困惑。我对java有点陌生,我正在尝试写一些东西,以便当您在eclipse中运行代码时,控制台会询问您的电子邮件地址,您输入它,它会将email1从:
字符串 email1 = "";
致:
字符串 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();
关于java - 如何在eclipse中使用Java控制台更改字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28564590/