“Anagrama java” Respostas de código

Programa Java Anagrama

import java.util.Arrays;  
   
public class AnagramString {  
    static void isAnagram(String str1, String str2) {  
        String s1 = str1.replaceAll("\\s", "");  
        String s2 = str2.replaceAll("\\s", "");  
        boolean status = true;  
        if (s1.length() != s2.length()) {  
            status = false;  
        } else {  
            char[] ArrayS1 = s1.toLowerCase().toCharArray();  
            char[] ArrayS2 = s2.toLowerCase().toCharArray();  
            Arrays.sort(ArrayS1);  
            Arrays.sort(ArrayS2);  
            status = Arrays.equals(ArrayS1, ArrayS2);  
        }  
        if (status) {  
            System.out.println(s1 + " and " + s2 + " are anagrams");  
        } else {  
            System.out.println(s1 + " and " + s2 + " are not anagrams");  
        }  
    }  
   
    public static void main(String[] args) {  
        isAnagram("Keep", "Peek");  
        isAnagram("Mother In Law", "Hitler Woman");  
    }  
}  
ishvinder singh

Anagrama java

public class Anagram {
	
	public static void main(String[] args) {
		
		System.out.println("is Anagram >>>>" + isAnagram("aabs", "baas"));
	}

	private static boolean isAnagram(String s1, String s2) {
		
		int[] count = new int[256];
		
		boolean result = true;
		
		for (int i = 0; i < s1.length(); i++) {
			
			count[s1.charAt(i)]++;
			count[s2.charAt(i)]--;
		}
		
		for (int i = 0; i < count.length; i++) {
			
			if(count[i] !=0) {
				result =false;
			}
			
		}
		return result;
		
	}

}
Gorgeous Grasshopper

Respostas semelhantes a “Anagrama java”

Perguntas semelhantes a “Anagrama java”

Mais respostas relacionadas para “Anagrama java” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código