menu
bartleby
search
close search
Hit Return to see all results

public static int createMirror(String str)write your code to calculate the number of characters that should be removed from a string so that it becomes a mirrored word.dont use 3rd party libraries and java.util

Question

public static int createMirror(String str)

write your code to calculate the number of characters that should be removed from a string so that it becomes a mirrored word.

dont use 3rd party libraries and java.util

check_circleAnswer
Step 1

A Java program is created to calculate the number of characters to be removed from a string to make it a mirrored word. The program is given below.

Step 2

public class Main

{

    final static int CHARACTERS = 26;

    static int createMirror(String str0, String str1)    // function is defined to calculate minimum numbers                      

                                                                                          //  of characters to be removed

    {

        int arr[] = new int[CHARACTERS];

        for (int i = 0; i < str0.length(); i++)     // frequency of each character is counted in first string

        {

            arr[str0.charAt(i) - 'a']++;

        }

        for (int i = 0; i < str1.length(); i++)      // frequency of each character is counted in second string

        {

            arr[str1.charAt(i) - 'a']--;

        }

        int res = 0;

        for (int i = 0; i < CHARACTERS; i++) {

            res += Math.abs(arr[i]);

        }

        return res;

    }

 

    static public void main(String[] args)

{

        String str0 = "pthernv", str1 = "her";

        System.out.println(createMirror(str0, str1));     //function is called

    }

}

Step 3

In the above program, a function createMirror is defined that will calculate the number of characters required to be removed to make the two strings same. In that function definition, arrays are created for both the strings to count their...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Linw servers PROJECTNAME, script that given Create 2. directory named dircctory t. The name it will ...

A: T1 contains 24 voice channels, and the 8th bit is used for signaling in a channel. Hence, out of 193...

question_answer

Q: In Python 3.7.4 Write a program that will compute the total cost of an amazon purchase. The program ...

A: ProgramSince two questions have been given and it is not clear the answer is sought for which questi...

question_answer

Q: Subject: Computer Organization I 1.a) How many milliseconds (ms) are in 1 second?b) How many microse...

A: ConceptTo solve this, we usually take the time in the power of 10.In 1 second, there are 1,000 milli...

question_answer

Q: What type of technique is used when an image is transferred by forcing ink through fine mesh or silk...

A: SerigraphySerigraphy also known as screen printing or silkscreen printing is a printing technique wh...

question_answer

Q: In a computer instruction format, the instruction length is 11 bits and the size of an address field...

A: Given:Instruction length = 11 bits = 211 = 2048 bitsAddress register size = 4 bits

question_answer

Q: Why is it important for you to know about compressed zip files and folders

A: Compressed ZIP files and foldersCompressed ZIP files are the files that pack one or more computer fi...

question_answer

Q: Read in 5 letters from the keyboard, reverse the order of the second and next to last letters, and p...

A: Program to reading 5 letters from the keyboards and reversing the order of the second and next to la...

question_answer

Q: Write a program in c++ to generate a random number between 1 - 100, and then display which quartile ...

A: Program plan:Include the required header files into the program.Define the main function.Declare the...

question_answer

Q: Question: Write a program that prompts the user to enter the number of students and each student's s...

A: Solution:The python program has the following algorithm:Prompt and read the total number of students...

Sorry about that. What wasn’t helpful?