How to reverse a string in Java

In this Problem we learn how to Reverse a String in Java. User will Enter a string and that string pass to the parameter of another string which has function to reverse the user string. At the end of the program the program will display string before reversing and after reversing.

Source Code 


package com.ancodingpoint.ww.w;
import java.util.Scanner;

public class String_Function {

    public static void main(String[] args) {
       Scanner input = new Scanner (System.in);
       String sentence = "";
        System.out.println(" Enter your Story Here .... ! ");
       sentence = input.nextLine();
       String reverse = new StringBuffer(sentence).reverse().toString();
       System.out.println("  \n Your Story Before Reverse \n " + sentence);
       System.out.println("  \n Your Story After Reversing the String \n " + reverse);
       
    } 
}

Output of the Program


Java String Programming


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment