Menu
Question Index
...


Write a program to find the moves to form the required word using the given character sequence. As shown below for getting the required word 'Raman' from the character sequence 'amnR', we have move to 3 characters to print R, 1 character for a, 1 for m, 3 for a and 2 for n.

Input (Character array, String) Output (Integer array)
{'a', 'm', 'n', 'R'}, Raman {3, 1, 1, 3, 2}
{'a', 'd', 'e', 'i', 'k', 'n', 'V', 'v'}, Vivekananda {6, 5, 4, 3, 2, 4, 5, 3, 5, 4, 7}
{'a', 'j', 'm', 'n', 'k', 'R', 'u'}, Ramanujan {5, 2, 2, 5, 3, 3, 2, 6, 3}
{'a', 'b', 'r', 't', 'y'}, aryabatta {0, 2, 2, 1, 1, 4, 3, 0, 2}

class FindMovesToFormWord

{    public static void main(String s[])
    {
        char input[] = {'a', 'd', 'e', 'i', 'k', 'n', 'V', 'v'};
        System.out.print("The moves are : ");
        for (int value : getMoves(input, "Vivekananda")) {
        System.out.print(value + " ");
        }

    }


public static int[] getMoves(char[] input, String inputString) {
//Write code here to get the moves to form the required word using the given character sequence
}
}

Doubts

Problems

Topic: Java Character Extraction - toCharArray() Method In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App