i'm having bit of trouble trying figure out how prevent user input numerical. understand how prevent non-numerical inputs (ie. inputting letter instead of number) not other way around. how work around this?
string[] player_name = new string[game]; (i = 0; < game; i++) { try { player_name[i] = joptionpane.showinputdialog("enter name of player, 1 one. "); } catch(exception e) { joptionpane.showmessagedialog(null, "enter valid name!"); i--; }
use do/while statement. "do input while input contains @ last 1 number".
string[] player_name = new string[game]; (int = 0; < game; i++) { string input; { input = joptionpane.showinputdialog("enter name of player, 1 one. "); } while (input.matches(".*\\d+.*")); player_name[i] = input; }
Comments
Post a Comment