Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created October 23, 2011 08:04
Show Gist options
  • Save ellbur/1307032 to your computer and use it in GitHub Desktop.
Save ellbur/1307032 to your computer and use it in GitHub Desktop.
Anagram puzzle
public class Anagram {
public static void main(String[] args) {
String a = IO.readString();
String b = IO.readString();
boolean anagram = true;
int count = 0;
if (a.length()==b.length()) {
for ( int i = 0 ; i < a.length() ; i++) {
char x = a.charAt(i);
for ( int j = 0 ; j < b.length() ; j++ ) {
if (x==b.charAt(j)) {
count++;
}
if (x==a.charAt(j)) {
count--;
}
}
if (count!=0) {
anagram = false;
}
}
} else {
anagram = false;
}
System.out.println(anagram);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment