0

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!

3
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by webmasts
0

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

if ( s.length() >= 5 ) {
  // Proceed
}
0

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. :)

0

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

This question has already been answered. 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.