Write a program to reverse a string


import java.util.Scanner;

public class StringReversal {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a string: ");

String inputString = scanner.nextLine();

String reversedString = reverseString(inputString);

System.out.println("Reversed string: " + reversedString);


public static String reverseString(String inputString) {

String reversedString = "";

for (int i = inputString.length() - 1; i >= 0; i--) {

reversedString += inputString.charAt(i);


return reversedString;



Program to reverse a stringUse a loop to iterate through the string and append each character to a new string in reverse orderAlternatively, use built-in string functions like reverse() or slice()...
see more
Add answer anonymously...
Wittybrains Software Technologies Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
55 L+


5 L+


2 Cr+


1 Cr+


Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2023 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Hello, Guest
Contribute to help millions!
Write a review
Share interview
Contribute salary
Add office photos
Add office benefits