+ 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
2 ответов
+ 4
String pass = "****";
// take input
if( pass.length() != 4){
System.out.println("try new pin with 4 digit");
}else{
// your code
}
- 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