WAP to take a string as input and display reverse String

import java.util.*; class T16 { public static void main(String[] args) { String str, reversed = ""; Scanner sc = new Scanner(System.in); System.out.print("Enter your sentence : "); str = sc.nextLine(); for (int i = str.length() - 1; i >= 0; --i) { reversed += str.charAt(i); } System.out.println("reverse string is : " + reversed); } } Copy Code
Expected Output:

Enter your sentence : Hardik Srivastava
reverse string is : avatsavirS kidraH