This application accepts user input from the console and then prints the reverse of the user input to the console. The last string that this program should print is the reverse user input.
JAVA
Solution:
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args)
{
//standerd input stream
Scanner sc= new
Scanner(System.in);
//taking string as input
String st =
sc.nextLine();
// converting
string to string buffer
StringBuffer s = new
StringBuffer(st);
//reverse() reverses the string
s.reverse();
//printing the reversed
string
System.out.println(s);
}
}
Note: If you find any error in the above code it may be due to different name of file , so please save your file with name Main.java
If you find my answer helpful,please give thumbs up
Get Answers For Free
Most questions answered within 1 hours.