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


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

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


Computer Science


Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add

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...


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...


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...


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...


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


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...


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...


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...


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?