D. Write a program to input any sentence and display if from
reverse order?
Example: Input "world" Output: "drow"
Answers
Answered by
2
Correct Question.
- Write a program to input any word and display it in reverse order. Example - Input: "World", Output: "dlroW".
The Code.
import java.util.*;
public class Reverse{
public static void main(String s[]){
System.out.print("Enter a string: ");
String str=(new Scanner(System.in)).next();
String rev="";
for(int i=str.length()-1;i>-1;rev+=str.charAt(i),i--);
System.out.println("Reversed String: "+rev);
}
}
Sample I/O.
Enter a string: Hello!
Reversed String: !olleH
See attachment for verification.
Attachments:
Similar questions