Hi,

I am creating a RPG Character Generator and I have a InputDialog box which asks the user to enter there characters name.

I have a do while loop to check for if the user entered a character which allows runs through the code if the users enters a correct character name but if the user enters a character name less than 3 characters or more than 12 then it will ignore that name and show the Dialog box again.

The only thing is the program quits if the users presses OK without entering a name.

How would I stop this from happening?

Thanks, Ross

This is what I have so far

do
	 {
		 String inputString  = JOptionPane.showInputDialog(null,"What Is The Name Of Your Character ?");
     	 Scanner nameScanner = new Scanner(inputString);               
     	 firstName = nameScanner.next();
     	 String outputString = "The Character Name Is "+ firstName;
 	 }
     while (firstName.length() < 3 || firstName.length() > 12);

Edited 6 Years Ago by RossMc: n/a

Tried it and the program still closes when the OK button is pressed with no name entered.

String inputString ="";
do
		  
		      {
		  
		       inputString = JOptionPane.showInputDialog(null,"What Is The Name Of Your Character ?");
		   
		   
		      }
		   
		     while (inputString.length() < 3 || inputString.length() > 12);

		      Scanner nameScanner = new Scanner(inputString);
		   
		      firstName = nameScanner.next();
		   
		      String outputString = "The Character Name Is "+ firstName;

Edited 6 Years Ago by musthafa.aj: n/a

This article has been dead for over six months. Start a new discussion instead.