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(System.in); String input = sc.nextLine(); //We will reverse the String using StringBuilder. StringBuilder sb=new StringBuilder(input); //Now reverse the input value and print System.out.println(sb.reverse().toString()); } }  

Reverse a String in Java 6 months 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(System.in);
        String input = sc.nextLine();
        
        //We will reverse the String using StringBuilder.
        StringBuilder sb=new StringBuilder(input);
       
        //Now reverse the input value and print 
        System.out.println(sb.reverse().toString());
       
    }
}