How can I set limits on how many characters can be inputted? (Java) -
do{ out.println("\n---------------------------------"); out.println("---------------------------------"); out.print("please type acces card number: "); try{ card = input.nextint(); if(card.length != 10){ out.println("the number typed incorrect"); out.println("the number must 10 numbers long"); continue; } } catch(inputmismatchexception ex){ } }while(true);
im trying make card 10 characters long. (1234567890), , if user inputs (123) or (123456789098723) error message should appear. card.length doesnt seem work.
just change int string
string card = input.next(); if(card.length() != 10){ //do }
you can convert int later
int value = integer.parseint(card);
Comments
Post a Comment