java - 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 - 我怎样才能在java中更快地做到这一点?复制长字符串的字符
- c++ - 三向比较取代了除 == 之外的所有其他比较运算符?
- reactjs - 未捕获的 DOMException:无法在“IDBObjectStore”上执行“删除”:事务未处于活动状态
- macos - 为节点 v12 安装 babel cli 时出现奇怪的错误日志
- java - 使用 OR-Tools 表达多变量约束
- pytorch - 强化学习中是否有任何方法可以选择多个同时动作?
- c# - 我想创建一个 Excel 电子表格,其中每个工作表都是一个列表。关于如何做到这一点的任何建议。我需要列出清单吗?
- javascript - React,JS - 使用 refs 的不同方式的功能差异
- gradle - 为什么 gradle publish 正在运行最后一个任务
- google-apps-script - Google 表单审批工作流程 | Apps 脚本中的问题:“执行该操作需要授权。”