Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
You are given a text file named sentences.txt, which contains a list of sentences separated by newline characters. Each sentence is composed of words separated by spaces. Your task is to read the sentences, reverse each sentence, and then output the reversed sentences.

Input Format

The first line contains the number of sentences.
Following lines containes the sentences.
Hint: Standard Input : Scanner Class

Constraints

The length of each sentence does not exceed 100 characters.
The number of sentences in the input file does not exceed 100.
Output Format

Output the sentences in reversed manner.
Hint: Use StringBuilder | StringBuffer for easy reversal of sentences.

Sample Input 0

17
Programming is not hard.
Not sure if it's true.
Yes, it's true.

dog lazy the over jumps fox brown quick The.
nine saves time in stitch A.
beholder the of eye the in is Beauty.
words than louder speak Actions.
chocolates of box a like is Life.
worm the catches bird early The.
well ends well that All's.
perfect makes Practice.
way a there's will, a there's Where.
never than late Better.

more There's.
kidding Just.


Sample Output 0
hard not is Programming.
true it's if sure Not.
true it's, Yes.

The quick brown fox jumps over the lazy dog.
A stitch in time saves nine.
Beauty is in the eye of the beholder.
Actions speak louder than words.
Life is like a box of chocolates.
The early bird catches the worm.
All's that well ends well.
Practice makes perfect.
Where there's a will, there's a way.
Better late than never.

There's more.
Just kidding.


Java
1
import java.io.*;
2
import java.util.*;
3

4
public class Solution {
5

6
    public static void main(String[] args) {
7
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
8
    }
9
}


What I have tried:

I tried but in the sentence true it's, Yes.
there is a comma before the period
Posted
Updated 8-Apr-24 9:34am
v2
Comments
PIEBALDconsult 8-Apr-24 15:36pm    
I'd sooner use a Stack than a StringBuilder.

1 solution

You have all the information you need in the assignment. We don't write the answer to assignments, as this won't benefit you.

Take the question, and break it down. Work out what you, as a human, would do in small logical steps. If you get code that's not working, ask here and we'll help, but try to have a go yourself first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900