Created
November 8, 2015 20:18
-
-
Save edinak1/3eb79e6daf2712555977 to your computer and use it in GitHub Desktop.
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
package test; | |
public class Invers { | |
public static void main(String[] args) { | |
String str="abcd efgh iklmnop"; | |
String str1=null; | |
String str2="a"; | |
String str3=" "; | |
String str4="aba"; | |
System.out.println(inverse(str)); | |
System.out.println(inverse(str1)); | |
System.out.println(inverse(str2)); | |
System.out.println(inverse(str3)); | |
System.out.println(inverse(str4)); | |
} | |
static String inverse(String str) | |
{ | |
if(str==null || str.length()<1) | |
return "Give me another string"; | |
if(str.length()==1) | |
return"Only one symvol, inversion have no sense"; | |
char[]ar=str.toCharArray(); | |
char temp; | |
boolean flag=false; | |
for(int i=0,j=ar.length-1; i<=j ; i++,j--) | |
{ | |
if(ar[i]!=ar[j]) | |
{ | |
temp=ar[i]; | |
ar[i]=ar[j]; | |
ar[j]=temp; | |
flag=true; | |
} | |
} | |
if(flag) | |
return new String(ar); | |
return "Polindrom, inversion have no sense"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment