Character array question
i have been working on this for the past 20 minutes or so and can not figure this out. i want to create a character array of 5 elements. and create a JOptionPane to ask the user to enter the characters.
the problem i am having is that the error message says i need char instead of string. i do not know how to convert a string to a char.
this is what i have
char[] charArray =newchar[5];
for(int x = 0; x < charArray.length; x++)
charArray[x] = JOptionPane.showInputDialog("Please enter a character:" );
I don't do GUIs, and since you didn't paste the error message, this is only a guess, but I would imagine that showInputDialog returns a String. A String is NOT a char[], nor is it a char.
It's not clear what exactly you're trying to do. Either use String's charAt method to get the char you want from the String, or use its toCharArray (or something like that) method to convert the String into an array of characters and get the one you want after that.
Note taht what you're trying to do now will display 5 dialogs (since charArray.lengh is 5).
> > thank you guys, the code Captain Morgan gave me> works.> > Until the user presses the cancel button, or types> nothing before pressing Okay :-)Pffff, like that's gonna happen.