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
In the ____________________ technique, the virus is divided into several parts and the parts are placed at random positions thro
shusha [124]

Answer:

Split Infection

Explanation:

In the split infection technique, each time the file is opened either by the user or the system operating system, the virus copy itself into another file on the same system and unload malicious payloads to perform some actions. While this is ongoing, the virus erase file from the user hard drive and might even go as formatting the hard disk drive.

It should be noted that the virus cannot transfer itself from one computer to another

5 0
3 years ago
In your opinion is it more beneficial to have many folders or is it better to nest subfolders
Semmy [17]
I dont think it matters just as long you have all your things to work it doesnt matter if you have to tape it on your back
7 0
2 years ago
When an application contains just one version of a method, you can call the method using a(n) ____ of the correct data type.
faltersainse [42]

Answer:

Parameter

Explanation:

q: When an application contains just one version of a method, you can call the method using a(n) ____ of the correct data type.

a: Parameter

3 0
3 years ago
How many responses does a computer expect to receive when it broadcasts an ARP request?why?
Alla [95]

Answer: The response that is expected when it broadcast an ARP request is one or zero.

Explanation: ARP request means Address Resolution Protocol which is a protocol responsible for the mapping of the IP(Internet protocol)address of a system to the MAC(Media Access Control) layer. Only one response is received only if the IP address is present in the ARP otherwise if the IP address does not matches then no response is returned.Thus only one or zero response can be received when a ARP request is process.

5 0
2 years ago
A command, such as a button or keyboard shortcut, that performs a specific task is known as a
Oxana [17]

Answer:

Macro

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • True or False. It is required to restart the client computer after the DLP agent has been installed.
    9·2 answers
  • Proxy data:
    12·1 answer
  • Which command can be used to manually add a package to the driver store?
    13·1 answer
  • Select the correct answer.
    9·1 answer
  • Alison wants to add her company name at the bottom of every page in her document. Which option should she use?
    11·2 answers
  • Ideally an entity identifier is composed of _____ attribute(s).
    11·1 answer
  • What is application software? A computer language for accessing data in a database. A character string used to identify the loca
    10·1 answer
  • What is a third variable condition that could create the following correlation?
    10·2 answers
  • According to Okun's law, if the unemployment rate goes from 7% to 4%, what
    15·1 answer
  • If you walked into a room containing three computers and were told one of them was infected with malware, how would you determin
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!