Reverse a String in Java 1 year ago

In this program we will reverse an input String and print the reversed String.

We will use StringBuilder to achieve the reversal.

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(;
        String input = sc.nextLine();
        //We will reverse the String using StringBuilder.
        StringBuilder sb=new StringBuilder(input);
        //Now reverse the input value and print