Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, write a program that tests whether two words are anagrams (use exactly the same letters the same number of times): Thank you in

In Java, write a program that tests whether two words are anagrams (use exactly the same letters the same number of times):

Thank you in advance!

P.S. I have found similar answers but they do not follow these parameters

image text in transcribed

Anagrams Project Write a program that tests whether two words are anagrams (use exactly the same letters the same number of times) Enter first word: smartest. Enter second word: mattress The words are anagrams. Enter first word: dumbest Enter second word: stumble The words are not anagrams. Procedure: Step 1. Create the method: void countLetters (String word, int[] counts) The variable counts is an array of 26 integers used to keep track of how many times each letter appears in word. Each element in counts holds the count for a single letter. Element O holds the count for the letter 'A', Element 1 holds the count for the letter 'B' etc. For example, after the word smartest has been read, the array should contain the values 1000 10000000 10000 122000000, smartest contains one a, one e, one m, one r, two s's and two t's. To find which index you should increment for a letter: 1. convert the letter to UPPERCASE 2. find the index of that letter in a class constant that contains every uppercase letter of the alphabet i.e. "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 3. increment the element in counts using that index. Do the above in a loop until you have counted the appearance of every letter in word To test this method, create an array of 26 ints, and pass in it and nonsense words like "abbccc". When the method returns, use the printArray method you created last class to check if the array has the correct values. Step 2 In main create two arrays to hold letter counts for two words. (If you are going to reuse the array that you created in Step 1, remember that it will contain numbers from your testing so comment out that test code). Prompt the user for two words. Then call countLetters twice, once for each of the words entered by the user. Check if the two arrays holding the letter counts are the same. If they are, print a message saying the words are anagrams. If they are not, print a message saying they are not

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

What is the best time for a firm to develop its business model?

Answered: 1 week ago

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago