gpt4 book ai didi

java - java中的密码检查器与do while

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:46 24 4
gpt4 key购买 nike

我需要编写一个密码检查器来确保密码正确。

首先我提示用户输入密码

其次,我提示用户重新输入密码

第三,我需要检查密码是否相同

但此步骤需要重复1到3,直到密码正确输入两次。

这是我的代码。但我无法理解重复1到3的逻辑

import java.util.*;

public class Lab4Exercise1{
public static void main(String[] args){

System.out.print("Enter Your password");
Scanner sc = new Scanner(System.in);
double password = sc.nextDouble;
double reentered = sc.nextDouble;

do {

}while (password==reentered);
}
}

最佳答案

试试这个

import java.util.*;

public class Lab4Exercise1{
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
double password;
double reentered;
do {
System.out.println("(Re)Enter Password:");
password = sc.nextDouble();
System.out.println("Confirm Password:");
reentered = sc.nextDouble();
} while (password != reentered);

}
}

关于java - java中的密码检查器与do while,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39797900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com