Created
March 14, 2019 11:03
-
-
Save ShubhamS32/d068e7b014888bb5bc4b7b9e85f18e63 to your computer and use it in GitHub Desktop.
To Reverse String without using String Buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.pre; | |
| public class ReverseString { | |
| public static void main(String[] args) { | |
| // TODO Auto-generated method stub | |
| String word="shubham"; | |
| char[] warray=word.toCharArray(); | |
| char[] farray= new char[warray.length]; | |
| System.out.println("Length :"+warray.length); | |
| int k=0; | |
| for(int i=(warray.length-1);i>=0;i--) | |
| { | |
| System.out.println(warray[i]); | |
| farray[k]=warray[i]; | |
| System.out.println(farray[i]); | |
| k++; | |
| } | |
| String reverseString = new String(farray); | |
| System.out.println("reverseString : "+reverseString); | |
| String rString = String.copyValueOf(farray); | |
| System.out.println("RString :"+rString); | |
| System.out.println(farray); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment