Emrah Sarıboz Emrah Sarıboz - 2 months ago 14
Java Question

Password Checker in java with do while

I need to write a password checker which ensures that password correct.

Firstly I prompt the user enter the password

Secondly, I prompt the user to reenter the password

thirdly, I need to check that the passwords are identical

But this steps need to repeat 1 through 3 until password is correctly entered twice.

Here is my code. But i cant understand the logic of repeat 1 through 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);
}
}

Answer

Try this

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

    }
}