aspose file tools*
The moose likes Beginning Java and the fly likes how to declare the length of the word entered? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to declare the length of the word entered?" Watch "how to declare the length of the word entered?" New topic
Author

how to declare the length of the word entered?

Jack Bolton
Ranch Hand

Joined: May 08, 2006
Posts: 65
i have now declared an array of String, to capture five words, but i want that every word entered to have a length of 10 letters only.

where do i have to specify that length?


marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It sounds like you need to write some validation code around your readLine() method.

while(palab[i].length() != 10) {...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jack Bolton
Ranch Hand

Joined: May 08, 2006
Posts: 65
you mean like this?
its not working
did i declared it right?

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The validation code would just be used to make sure that the input is a 10-letter word.
Jack Bolton
Ranch Hand

Joined: May 08, 2006
Posts: 65
ok, it's working,
but there is a doubt that i'm having.
I declared a String array to capture five words. String[5]. So everytime i enter a word it takes an element of the array.
But i want that when i enter a word that is longer than 10 letters, it doesn't take an element of the array. So the program will always print the five words encripted.
How do i code this?

here is my code:

[ May 20, 2006: Message edited by: Jack Bolton ]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Jack Bolton
Ranch Hand

Joined: May 08, 2006
Posts: 65
thanks wise owen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to declare the length of the word entered?