954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

finding the length in java

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!

webmasts
Newbie Poster
21 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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

if ( s.length() >= 5 ) {
  // Proceed
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

webmasts
Newbie Poster
21 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You