TP interview question

Write a code to reverse a string

Interview Answer

Anonymous

18 May 2026

public class ReverseString { public static void main(String[] args) { String str = "Hello"; String reversed = ""; for (int i = str.length() - 1; i >= 0; i--) { reversed += str.charAt(i); } System.out.println("Reversed String: " + reversed); } }