An exercise that I am stuck on is one using the do-while loop. I am supposed to prompt the user to enter the password, then re-enter the password again. If these passwords match then they will gain access. If the two passwords do not match then I am supposed to prompt the user to enter the password again 3 more times. After the third time it will tell them access is denied. I am having difficulty distinguishing what goes where in the do-while loop.
This is what I have (updated)...still confused as to why it is not terminating:
import java.util.Scanner;
public class PasswordChecker{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String password1;
String password2;
int i = 1;
do {
System.out.println("Please enter your password");
password1 = sc.nextLine();
System.out.println("Please re-enter your password");
password2 = sc.nextLine();
} while(!password1.equals(password2) && i<=3);
i++;
}
}