Hi,

I'm creating a palindrome program. So far, I got that part. Now, I need to find out if the length of the integer (string) is less than 5 digits. If the length is less than 5, then don't proceed with the program. Please give your suggestions. Thanks!

Recommended Answers

All 3 Replies

>I need to find out if the length of the integer (string) is less than 5 digits.
Um...

if ( s.length() >= 5 ) {
  // Proceed
}
Member Avatar for iamthwee

Hi,

I'm creating a palindrome program. So far, I got that part. Now, I need to find out if the length of the integer (string) is less than 5 digits. If the length is less than 5, then don't proceed with the program. Please give your suggestions. Thanks!

Come, come now webmasts, surely if you have already successfully created a palindrome program you should know how to get the length. ;) -Or is this a GUI problem?

Anyway if you have further problems post this in the java forum. :)

Actually, I tried using the above code for finding the length, but it doesn't work. Anyways, I will try again. I get the following error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at _uesJavaRun.main(_uesJavaRun.java:29)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.charAt(String.java:558)
at palindrome.main(palindrome.java:26)
... 5 more

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.