• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays and exceptions!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been struggling this past week trying to write a class that will allow a user to enter a line of text that is suppose to be less than 20 characters long. If this string is greater than 20 characters long then it is suppose to throw it out and ask the user to re-enter the message. I have been ablet to write the array to store the line of text and have been able to retreive whatever character I need to. I can not figure out how to create a statement that is looking for less than 20 characters that has to deal with characters. Any help, suggestions, or CODE preferable would be greatly appreciated. Thanks in advance!

Rich
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at documentation about arrays and the String API?

We're not going to write your homework code for you.
 
Richard Java
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read quite a lot including many post in here and on Sun forums. I am not wanting my homework code written for me either. Actually I figured out my biggest problem. I did not need to be using a Array but rather a string. I have finally got everything working besides asking the user to repeat the task because he has entered to many characters. There is a lot of good information in these forums and I did not mean to imply I wanted anyone to do my homework for me I just reached an impass I was trying to get pointed in the right direction. Thanks for the kick in the butt!

Rich
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You shuould try to read String API.
If those user's entry is a string, you can get the length of that.
After that you can add the condition whether the lenght of that string less than 20 character or not..

I think that is a point of your problem..
Hope this helps you...
Correct me if I am wrong.

thanks
daniel
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for repeating the request for input, you might find a while loop helpful.

Layne
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the future, you will get better help if you post the code you have written so far. We'll be glad to point you to the next step.

PS: When you do post code, please use code tags to preserve your indentation. It makes reading code much easier.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic