Last active
December 12, 2015 05:59
-
-
Save linusthe3rd/4726261 to your computer and use it in GitHub Desktop.
reverse a string in java
This file contains 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
class Reverse { | |
public static void main(String[] args) { | |
reverse("abcde"); | |
} | |
public static void reverse(String str){ | |
char[] str_arr = str.toCharArray(); | |
int start = 0, | |
end = str_arr.length-1; | |
while (start < end){ | |
char temp = str_arr[start]; | |
str_arr[start] = str_arr[end]; | |
str_arr[end] = temp; | |
start++; | |
end--; | |
} | |
System.out.println(str_arr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment