This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Arrays and exceptions! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays and exceptions!" Watch "Arrays and exceptions!" New topic
Author

Arrays and exceptions!

Richard Java
Greenhorn

Joined: Feb 10, 2005
Posts: 5
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
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Feb 10, 2005
Posts: 5
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
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As for repeating the request for input, you might find a while loop helpful.

Layne


Java API Documentation
The Java Tutorial
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
 
GeeCON Prague 2014
 
subject: Arrays and exceptions!