Java program to accept a string and display in reverse

Write a Java program to accept a string and Write a function to display the string in reverse.

Input: coderegister


Output: retsigeredoc




Java Implementation:


import java.util.*;
import java.lang.*;
import java.io.*;

class CodeRegister
{
 public static void main (String[] args) throws java.lang.Exception
 {
  Scanner in = new Scanner(System.in);
  String str = in.next();
  displayInReverse(str);
 }
 
 static void displayInReverse(String str)
 {
  for(int i = str.length()-1 ; i >= 0 ; i--)
   System.out.print(str.charAt(i));
 }
}