Pls give me a code for my full understanding. My code is empty, because i tired and delete her
1. Read a file name from the console. Read the contents of the file.
2. For each line in the file:
2.1. reverse the order of all characters.
2.2. display the result.
3. Close the streams.
Example input file: I'm a programmer.
Amigo
Example result: .remmargorp a m'I
ogimA
Requirements:
The program must read the file name from the console (use BufferedReader).
The BufferedReader used for reading input from the console must be closed after use.
The program must read the file's contents (use FileReader).
The file input stream (FileReader) must be closed.
The program should display all of the characters from the file in reverse order.
package com.codegym.task.task19.task1926;
/*
Mirror image
*/
public class Solution {
public static void main(String[] args) {
}
}
I guess there are two main ways to solve this task:
-using StringBuilder class and its methods
-manual reversing.
The last one is also pretty simple, let's use KISS methodology.
Each string is in fact array of chars.
So just reverse that array, and then yet again convert to string.
Also don't forget to google, just type "how to reverse string java" and you will get thousands of possible variants.
You simply read a filename from the counsel.
Open the file with a FileReader.
Read each line in the file.
Reverse the order of the charaters in each line.
Print out the the reversed string.
Close the FileReader.
+1
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.