Created
January 12, 2016 14:52
-
-
Save Yur-ok/4f583fac32718fb1255b to your computer and use it in GitHub Desktop.
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 Lesson3.KeyPoint5; | |
import java.util.Arrays; | |
/** | |
* Created by Юрий on 12.01.2016. | |
*/ | |
public class StringInverse { | |
public static void main(String[] args) { | |
System.out.println(inverse("Yurok")); | |
System.out.println(inverse("Programmer")); | |
} | |
static String inverse(String str) { | |
char[] arr = str.toCharArray(); | |
char[] tmp = new char[arr.length]; | |
int count = arr.length - 1; | |
for (int i = 0; count >= 0; i++) { | |
tmp[count] = arr[i]; | |
count--; | |
} | |
return new String(tmp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Как обычно забыли проверку на null.