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

Recommended Answers

All 5 Replies

please post your code so far you tried....

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);
while (firstName.length() > 3 && firstName.length() <12);

you try it and reply...

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.