logo image

Java program to print given string in reverse order



Following program shows you how to print given string in reverse order.

import java.util.Scanner;

public class StringOperations10 {

	public static void main(String[] args) {

		String input;
		String output = "";

		Scanner in = new Scanner(System.in);

		System.out.println("Please enter a string: ");

		input = in.nextLine();

		int length = input.length();

		for (int i = length; i > 0; i--)

			output = output + input.charAt(i - 1);

		System.out.println("Reverse of given string is: " + output);
	}
}

Output:

Please enter a string: 
hello
Reverse of given string is: olleh