Skip to content

Instantly share code, notes, and snippets.

@neojou
Created February 21, 2015 11:56
Show Gist options
  • Save neojou/79849de3876d45cd4155 to your computer and use it in GitHub Desktop.
Save neojou/79849de3876d45cd4155 to your computer and use it in GitHub Desktop.
java : MyString : if the words reversed is the same as original
package neo.lang;
import java.lang.String;
import static java.lang.System.out;
/**
*
* @author neojou
*/
public class MyString {
String str;
MyString(String s) {
str = s;
}
public boolean isMirror() {
int num = str.length();
for (int i=0; i<num/2; i++) {
if (str.charAt(i) != str.charAt(num-1-i)) return false;
}
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String[] words = {"RADAR", "WARTER START", "MILK KLIM", "RESERVERED", "IWI"};
for (int i=0; i<words.length; i++) {
out.print(words[i]);
MyString ms = new MyString(words[i]);
if ( ms.isMirror() ) {
out.print(" : Mirror");
}
out.println(" ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment