finding the length of a string
hi im pretty new to all this,
I am adding a part to my very basic program where the user can type "y" or "n" after they are being asked if they want to continue, I have been able to do this ok but im trying to make the program as air-tight as possible and i'm having troubble with the error checking.
I have told the program what to do next based on the first character the user has typed (character 0), I would like my prorgam to prevent continuation if more than one character was entered into the string. At present it still recognises ydr (example) as a valid entry, is there anyway i can detect if there is more than one character in the sting? by doing so i'll be able to throw back an error to the user.
do
{
System.out.println("Would you like to continue (y/n)");
System.out.println("");
tmpans = scan.nextLine();
if (tmpans.length > 1)
//i know the above method of detecting the length dosn't work with strings, is there an alternative?
{
exchar =true;
System.out.println("You have entered too many characters");
}
else
{
exchar =false;
}
while (exchar);
if (tmpans.charAt(0) =='y')
... etc

