Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Created January 12, 2016 14:52
Show Gist options
  • Save Yur-ok/4f583fac32718fb1255b to your computer and use it in GitHub Desktop.
Save Yur-ok/4f583fac32718fb1255b to your computer and use it in GitHub Desktop.
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);
}
}
@liuiv15
Copy link

liuiv15 commented Jan 21, 2016

Как обычно забыли проверку на null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment