+ 1

How can i prompt a user to enter a 4 digit pin?

I want to use loops, incase the user enters a pin greater or less then 4 digits I have been advised to use if statements and String but I'm struggling to get it right

7th May 2017, 6:54 PM
Theophilus Mashego
Theophilus Mashego - avatar
2 odpowiedzi
+ 4
String pass = "****"; // take input if( pass.length() != 4){ System.out.println("try new pin with 4 digit"); }else{ // your code }
7th May 2017, 7:06 PM
MR Programmer
MR Programmer - avatar
- 1
this is my code System.out.println("Please enter your four digit pin"); Scanner input = new Scanner (System.in); pin = input.nextInt(); String input = "****"; if (Input.length() != 4) { System.out.println("Error") } else { System.out.println("please continue") } // when the user enters more then 4 digits the error message does not print to screen the program continues to run and the message please continue is displayed
7th May 2017, 8:32 PM
Theophilus Mashego
Theophilus Mashego - avatar