Searching...
Friday, 9 December 2016

Program to reverse a String without using StringBuilder

07:17

Java program

package com.vinod.test;


/**
 * Example to reverse a String without using StringBuilder reverse method.
 *@authorvinodkariyathungalkumaran
 *
 */
public class ReverseStringExample {

    public static void main(String[] args) {
        String str = "My Name is Vinod";
        System.out.println("Input=" + str);
        String reverse = "";
        for (int i = str.length() - 1; i >= 0; i--) {
            reverse = reverse + str.charAt(i);
        }
        System.out.println("Output=" + reverse);
    }

}

Ouput

Input=My Name is Vinod
Output=doniV si emaN yM

0 comments: