JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
/*5.46
(Reverse a string)
Write a program that prompts the user to
enter a string and displays the string in
reverse order.
*/
public class StringReverse{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println(
"*** Reverse a string ***\n");
// Enter a string:
String s = "stimiL ruoY kearB";
// in.nextLine();
System.out.println(
"Input string : "+ s);
System.out.print(
"\nOutput string: ");
int len = s.length();
for (int i=len-1; i >= 0; i--){
char ch = s.charAt(i);
System.out.print(ch);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run