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]
2 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]2 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
A document with a(n) ____ guarantees that the document was indeed sent by a specific individual and that it hasn t been tampered
BARSIC [14]
The answer is A) digital signature
8 0
3 years ago
Tricia listed her assets and liabilities. Credit Card Bill Car Loan Bonds Piano Bank Account Bicycle Which are Tricia’s liabilit
DIA [1.3K]
<span>Her liabilities are her credit card bill and her car loan. These are things that she owes and has to pay off, so they are liabilities due to the fact that she owes for these items. Her bonds, piano, bank account, and bicycle are counted as assets.</span>
7 0
2 years ago
Read 2 more answers
The Securities and Exchange Commission (SEC) was created to develop and approve a set of common international accounting rules.
Dennis_Churaev [7]

Answer:  

Idk search it on google chrome

Explanation:

3 0
3 years ago
Live preview is available on a touch screen T/F
TEA [102]
<span>It is false that live preview is available on a touch screen. Life preview refers to cameras mostly, and to the fact that its display screen can be used as a viewfinder. Viewfinder is what you look through when you are using a camera to take a photo, or to focus on something. So, no, touch screen devices do not have this feature available, only the "old-school" cameras do.</span>
3 0
3 years ago
TIME REMAINING 01:48:57 What is the purpose of the website directory provided by the website host? to look up user account infor
muminat

Answer:

Cookie

Explanation:

its just because and also the answer is right on e 2020.

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which computing component is similar to the human brain
    6·2 answers
  • The ________ occurs when the user presses the enter key without typing a value for an input operation.
    5·1 answer
  • Binary is best interpreted by a computer because?
    8·2 answers
  • Josh's boss asked him to write a letter to their customers explaining some upcoming price increases. But Josh was in a hurry to
    8·2 answers
  • Help pleaseeeeeeeeeeeee
    13·2 answers
  • Is this a Bad Cpu processor ? I need some.help ASAP I turn on my.pc and it has no display but everything is on fans and the you
    13·1 answer
  • Using python:
    10·1 answer
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • A character with the point size of 10 is about 10/72 of once inch in height
    8·1 answer
  • What is the meaning of FTTH
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!