0

im having trouble with resetting my program.

Upon typing "y", the terminal skips all the steps to the end:

  • y
  • Enter an email address:
  • Email is not in the list Check another email? Y/N

it skips all the procedures straight to asking for another email.

import java.util.Scanner;
import java.util.Arrays;

public class emailValid {
    static Scanner sc = new Scanner(System.in);
    static String mail = "";
    static boolean start = false;
    static String[] emails = {"alex@gmail.com","bob@gmail.com"};

    public static void check(String email){
        boolean contains = Arrays.stream(emails).anyMatch(email::equals);
        if (contains == true) {
            System.out.println("Email is in the list");

        } else 
            System.out.println("Email is not in the list");

            
    }

    public static void main(String[] args) {
        do {
            System.out.println("Enter an email address:");
            mail = sc.nextLine();
            start = false;
            check(mail);
            System.out.println("Check another email? Y/N");
            char yes = sc.next().charAt(0);
            if (yes == 'Y' || yes == 'y') {
                start = true;
            } else 
                System.out.println("goodbye");
                



            
        } while (start != false);
    }
}
natisaver
  • 29
  • 5
  • Aside: all of your static variables (with the exception of the array of emails) should be local variables. And the array of emails would be easier as a list (or, even better, a Set), so you could just use the `contains` method. – Andy Turner Apr 17 '21 at 16:52

0 Answers0