• Post Reply Bookmark Topic Watch Topic
  • New Topic

constructing vectors of sentences  RSS feed

 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a program to reverse sentences (demarked by a period) in a paragraph (demarked by an empty line input from the console) using any list of your choice.
13. Create a vector that stores N numbers.

i need to reverse sentences in a paragraph.
the sentences end with a period and the paragraph ends with a newline.

i tried to construct Vector<String> and Vector<Vector> reading input from scanner, but that didn't work because scanner skips newlines.

what should i do?
can someone give me an algorithm to do this?
is there an example somewhere? ( i looked but couldn't find one)
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is incomprehensible because you haven't explained what you are doing. Please explain to us exactly what you are doing, and exactly what your code does. By doing that, you will explain it to yourself.

Do you know about Scanner#nextLine? Beware: I have yet to see a book which gives a good explanation of nextLine. Nor did the chap who complained about it in this thread. He had problems because he was getting empty Strings from nextLine; you might be able to turn nextLine's behaviour returning empty Strings to your advantage. You may need to investigate hasNext and hasNextLine, too. There are bound to be other ways to do what you want.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abigail Decan wrote:i need to reverse sentences in a paragraph.
the sentences end with a period and the paragraph ends with a newline.
...
i tried to construct Vector<String> and Vector<Vector> reading input from scanner, but that didn't work because scanner skips newlines.

In which case, back up to having a plan before you start coding.

The first two lines are great; the third one isn't, because you are already thinking about how you're going to code this. DON'T.

Questions:
1. What do you think is going to be the best object to store a "sentence" in?

2. Is your text going to be input in sentences? What if you get:
The quick brown
fox jumps over the
lazy dog today. Yesterday,
the flat cat sat
on the mat. And the day
before that, a bird in the
hand was worth two in
the bush.


3. Given a line of text, how do you know whether it contains the end of a sentence?

4. if it does contain the end of a sentence, what do you need to do?

Work out the issues first. In English. Then translate it to code.

HIH

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!