Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #1 #1313

Closed
wants to merge 1 commit into from
Closed

Reto #1 #1313

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/src/main/java/com/mouredev/weeklychallenge2022/Reto #1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.Arrays;

public class Anagramas {
public static void main(String[] args) {
String s1 ="amor";
String s2 = "roma";

if (esAnagrama(s1, s2)){
System.out.println("Si es un anagrama");
}else{
System.out.println("no son anagramas");
}
}

public static boolean esAnagrama (String s1, String s2){
s1 = s1.replaceAll("//s", "").toLowerCase();
s2 = s2.replaceAll("//s", "").toLowerCase();

if (s1.length() != s2.length()) {
return false;
}

char arr1 [] = s1.toCharArray();
char arr2 [] = s2.toCharArray();

Arrays.sort(arr1);
Arrays.sort(arr2);

return Arrays.equals(arr1,arr2);


}
}