Skip to content

Commit

Permalink
Merge pull request #418 from m-oliv/algos
Browse files Browse the repository at this point in the history
- Added the reverse string algorithm.
  • Loading branch information
ambujraj authored Oct 5, 2018
2 parents 0235ed1 + 57b5e79 commit c4ab357
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions reverse/ReverseString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ReverseString {
public static String reverseString(String s) {
char [] testArray = s.toCharArray();
int size = testArray.length / 2;
int i;
char temp;

for(i = 0; i<size; i++){
temp = testArray[i];
testArray[i] = testArray[testArray.length - i - 1];
testArray[testArray.length - i - 1] = temp;
}

return new String(testArray);
}

public static void main(String[] args) {
System.out.println(reverseString("test"));
}
}

0 comments on commit c4ab357

Please sign in to comment.