Hello all, I appreciate all the feedback I have received in regards to my
problem. But I should have mentioned that I was an absolut beginner to java
and to programming. I have a assignment that basically ask the user to enter
a sentence into the console.
I am using
String a;
a= Stdin.readln();
this will prompt the user to enter a sentence. Now I am confused with what
to do next. I have tried many things and know of them do what I want. I
managed to use the string tokenizer and yes it works great. But for this
assignment I need to know how to work with strings. Because if I don't I am
only cheating myself and wish not to do that.
I thought you only use
Integer.parseInt.(a);
for converting a string into an integer, but since I am working with words I
don't see the need for that. I know what I wish to do to solve the problem
but don't know exactly the java language in order to carry out my needs.
For example,
It would be wise to find out the lenght of the string first, then next where
the space occurs between the words so that I could separate the first word
from the others in the sentence. After that I would find the second space
inbetween the words to separate the 2nd word from the rest of the words in
the sentence. Then I would assign each word to print on a new line. That is
how I would approach this problem without programming. BUt then with OO, I
have this instinct that each separate problem should be its on object. For
example, an object for finding the lengh of string, then another object for
finding the space inbetween words, etc... And oh course I would give each
class its own methods to work from. BUt I don't know if this neccessary or
if I can just use one class to solve the entire problem with one main
method...Any more feedback, is always appreciated....
decoy@system102.com - 26 Sep 2005 23:01 GMT
To read a line via command prompt:
while(true)
{
System.out.print("your prompt: ");
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
String line = reader.readLine();
//do something....
}
Once you have this input into a String object there are a wealth of
functions available to manipulate this string, there is absolutely no
need to write your own. Just take a look at the String API docs for
more info:
http://java.sun.com/j2se/1.4.2/docs/api/
regards,
Stu.
Roedy Green - 26 Sep 2005 23:28 GMT
>I have a assignment that basically ask the user to enter
>a sentence into the console.
>I am using
That sounds a bit too easy for an assignment. It is just a readLine.
You can get the exact code from the file i/o Amanuensis at
http://mindprod.com/applets/fileio.html
What do you DO with the sentence once you have it? Don't you even at
least print it out?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Michael - 27 Sep 2005 03:38 GMT
yes the program is suppose to print back the results.
for example,
input,
java is fun!
output
java
is
fun!
>>I have a assignment that basically ask the user to enter
>>a sentence into the console.
[quoted text clipped - 6 lines]
> What do you DO with the sentence once you have it? Don't you even at
> least print it out?
Roedy Green - 27 Sep 2005 08:14 GMT
>output
>java
>
>is
>
>fun!
one word per line. OK that makes for a more challenging problem.
I would look into regex split. See
http://mindprod.com/jgloss/regex.html
for by far the easiest way to do it.
Your prof however might want you to do it with more primitive tools
since you likely have not been taught regex yet. In that case you
need to do it with a loop the looks for spaces and uses substring to
collect the bits for output. The trick part is making sure you handle
the first word, last word and double spaces. Concentrate first on
getting a middle word to work.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Hal Rosser - 30 Sep 2005 02:05 GMT
> yes the program is suppose to print back the results.
> for example,
[quoted text clipped - 8 lines]
>
> fun!
Take a look at the String's split method, so you can split the input
sentence string into an array of word strings.
Casey Hawthorne - 27 Sep 2005 04:19 GMT
Hi Roedy:
This may interest you!
Since I didn't realize it was possible in Agent to munge one's
address!
> Is it possible in the next version to have one email address for
> emailing and another munged email address for usenet posting?
Unless we remove it that function, sure. Agent has always been able
to do this. You can specify different "From:" addresses for Usenet
and Email.
To use the correct address for sending email, set your correct
information in Tools | Options | Posting Messages | User Identity.
This will also set your userid items in Folder | Default Propeties |
Posting Messages.
To set up an anti-spam address for each Usenet group that you post to,
go to Folder | Properties | Posting Messages | Fields. You can select
all groups at once, if you are configuring the same information for
all.
Select From then Override default value for From and enter your
anti-spam address.
When you "CC" Usenet posts, the Usenet anti-spam address is used. But
when Post New Email Message is used or you reply to an email, the
"e-mail" defaults are used.
--
Jeffrey Kaplan Agent Support Team www.forteinc.com
--
Regards,
Casey
Andrew Thompson - 27 Sep 2005 04:05 GMT
> ..BUt then with OO, I
> have this instinct that each separate problem should be its on object.
I disagree, and think you are 'overthinking' this problem.
It seems the tutor/teacher wants to test some fairly basic
stuff like understanding of loops.
Ask them, that is (part of) what they are being paid for.
> ..BUt I don't know if this neccessary or
> if I can just use one class to solve the entire problem with one main
> method..
I think that is the best way to go, unless the instructor
has stated otherwise.