0

Sorry that my title may be a little confusing. I am a little new to java and I am trying to write something so that when you run the code in eclipse, the console asks you for your email address, you input it and it changes email1 from:

String email1 = "";

To:

String email1 = "[email protected]";

Could someone tell me how to do this?

Here is my full code:

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");
        }
    }
}
1

1 Answer 1

2

Use the Scanner#nextLine() method to read a line of text from console.

// 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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.