0

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

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by musthafa.aj
0

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 by RossMc: n/a

0

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

0
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 by musthafa.aj: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.