1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Westkost [7]
3 years ago
13

Two strings, and , are called anagrams if they contain all the same characters in the same frequencies. For example, the anagram

s of CAT are CAT, ACT, TAC, TCA, ATC, and CTA. Complete the function in the editor. If and are case-insensitive anagrams, print "Anagrams"; otherwise, print "Not Anagrams" instead.
Computers and Technology
1 answer:
GenaCL600 [577]3 years ago
8 0

Answer:

static boolean isAnagram(String a, String b) {

<em> </em><em> </em><em>// 1 - Strings inequal in length can never be Anagram</em>

        if (a.length() != b.length()) {

             return false;

        }

<em> </em><em>        // 2 - Convert both Strings to Lower Case</em>

       a = a.toLowerCase();

        b = b.toLowerCase();

<em> </em><em>        // 3 - Create an Array to store character count</em>

        int charCount[] = new int[26];

<em>  </em><em>// 4 - Count Each Character</em>

        for (int i = 0; i < a.length(); i++) {

             charCount[a.charAt(i) - 97]++;

             charCount[b.charAt(i) - 97]--;

        }

       

<em>        </em><em> </em><em>// 5 - Check  for mismatching characters</em>

        for (int i = 0; i < charCount.length; i++) {

             if (charCount[i] != 0) {

                 return false;

            }

        }

       return true;

}

Explanation:

Complete Questions:

Two strings, a and b, are called anagrams if they contain all the same characters in the same frequencies. For example, the anagrams of CAT are CAT, ACT, TAC, TCA, ATC, and CTA. Complete the function in the editor. If and are case-insensitive anagrams, print "Anagrams"; otherwise, print "Not Anagrams" instead.

Function:

static boolean isAnagram(String a, String b) {

       // Complete the function

}

This algorithm has five steps to calculate whether two given strings are anagram or not.

  1. Check Strings length - If two strings don't have equal length, then they can never be anagrams. Because, anagrams contain <em>same characters in the same frequencies.</em>
  2. Convert both strings to lower case - in programming, <em>'A' is not equal to 'a'</em>. So, we need to make sure we have letters in same case to avoid such errors.
  3. Create an Array for character count - We need some method to ensure that the strings are anagrams. So, here we will count the characters and decide if the strings are anagrams (as discussed in next point)
  4. Count each character - If <u><em>String a</em></u><em> </em>has any character, we will <u><em>increase</em></u> the count of that character by 1. If <u><em>String b</em></u> has any character, we will <u><em>decrease</em></u> the count of that character by 1. At the end, if both strings have same characters in the same frequencies, all our character counts will be equal to 0.
  5. Check for mismatching characters - We check if all our character counts are equal to 0. If not, the function will return false, otherwise it will return true.
You might be interested in
Can you redact this image
spin [16.1K]

Answer:what???

Explanation:so

What

6 0
2 years ago
________ are viruses that masquerade as useful programs or files. hydras spyware programs worms adware programs trojan horses
Harrizon [31]
Trojan horse is the correct answer
5 0
3 years ago
Online databases allow you access to material you may not be able to find when using popular search engines like Google. Select
Anna007 [38]

Answer:

True

Explanation:

6 0
3 years ago
Is anyone excited for the new matrix coming out ?
Vinil7 [7]

Answer:

Yes, me!!

Explanation:

5 0
2 years ago
Read 2 more answers
____ convert a program design developed by a systems analyst or software developer using one of many computer languages.
erica [24]

Answer:

"Programmer " is the correct answer for the following question.

Explanation:

A programmer is a person who created the software They are basically a coder who develop a code for the program or the software. They are specialists in some in the programming code area. The programmer are writing the program for a different kind of software.

The main objective programmer they convert the program design which is developed  by a systems analyst or system designer using a different kind of computer language  

4 0
3 years ago
Other questions:
  • What is the maximum number of hosts you can have on a network if the first decimal value of the ip address is between 192 and 22
    10·1 answer
  • Given the three side lengths, how can you tell if a triangle<br>is a right triangle?​
    5·1 answer
  • A column letter above the grid, also called the ____, identifies each column.
    9·1 answer
  • Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your a
    10·1 answer
  • The blue bar across the top of the screen informs you of the Screen Title, or what step you are on.
    5·1 answer
  • When did outdoor air pollution first become a significant problem?
    9·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • Evolucion de los sistemas operativos
    5·1 answer
  • Fill in the blanks : To store 3 character a computer occupies...................bytes memory space​
    8·2 answers
  • The term technology is derived from the Chinese word. it is true or false​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!