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

[1733 byte] By [Nevabladea] at [2007-11-26 17:48:32]
# 1
String.getLength()
tjacobs01a at 2007-7-9 5:00:55 > top of Java-index,Java Essentials,New To Java...
# 2
so i'd replace (tmpans.length > 1)with (tmpans.getLength() > 1)?
Nevabladea at 2007-7-9 5:00:55 > top of Java-index,Java Essentials,New To Java...
# 3
> String.getLength()Errr... String.length() ?
sabre150a at 2007-7-9 5:00:55 > top of Java-index,Java Essentials,New To Java...
# 4
> > String.getLength()> > Errr... String.length() ?Ya right. Whatever. lolIt's still early in the day for me
tjacobs01a at 2007-7-9 5:00:55 > top of Java-index,Java Essentials,New To Java...
# 5
sorry i was being stupid forgot to add the "()" brackets, thanks
Nevabladea at 2007-7-9 5:00:55 > top of Java-index,Java Essentials,New To Java...