finding the length in java

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Feb 2006
Posts: 21
Reputation: webmasts is an unknown quantity at this point 
Solved Threads: 0
webmasts webmasts is offline Offline
Newbie Poster

finding the length in java

 
0
  #1
Mar 27th, 2006
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: finding the length in java

 
0
  #2
Mar 27th, 2006
>I need to find out if the length of the integer (string) is less than 5 digits.
Um...
if ( s.length() >= 5 ) {
  // Proceed
}
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: finding the length in java

 
0
  #3
Mar 27th, 2006
Originally Posted by webmasts
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 21
Reputation: webmasts is an unknown quantity at this point 
Solved Threads: 0
webmasts webmasts is offline Offline
Newbie Poster

Re: finding the length in java

 
0
  #4
Mar 27th, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC