Created
February 21, 2015 11:56
-
-
Save neojou/79849de3876d45cd4155 to your computer and use it in GitHub Desktop.
java : MyString : if the words reversed is the same as original
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 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