Thursday, August 31, 2017

Reverse A String in Java

In this article I would like to share with you a simple program that will ask the user to give any string and then our program will reverse the given string by our user using Java as our programming language. I am using Eclipse as my IDE in writing this program. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Reverse_String_Demo.java

/**
 * 
 */
package Reverse_String;

import java.util.*;

/**
 * @author Jacob
 *
 */
public class Reverse_String_Demo {

 public static String  Reverse_Me(String str) {
    
 String Rev_Str;
 
   Rev_Str = "";
   
       for(int a= str.length()-1; a>=0; a--) {
           Rev_Str = Rev_Str + str.charAt(a);
       }
       
       System.out.print("\n\n");
       System.out.println("The Reversed String is " + Rev_Str + ".");
       System.out.println();
       System.out.println("End of Program");
       System.out.println();
       return str; 
 }
/**
* @param args
*/
public static void main(String[] args) {
Scanner user_input =new Scanner(System.in);
String str_me;

        System.out.println();
        System.out.println("Reverse A String in Java");
        System.out.println();
        System.out.println("Written By Mr. Jake R. Pomperada, MAED-IT");
        System.out.println();
System.out.print("Enter any string: ");
        str_me = user_input.nextLine();
        
        Reverse_Me(str_me);
        
        user_input.close();

}

}




No comments:

Post a Comment