首页 > 解决方案 > Do While Loop to Restart Program 不断跳过程序(Java)

问题描述

我无法重置我的程序。

输入“y”后,终端会跳过所有步骤到最后:

它跳过所有程序直接要求另一封电子邮件。

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

标签: java

解决方案


推荐阅读