Write a program to find the remaining letter after striking out using the last stroke out character's value. Character value is nothing but 1 for A, 2 for B and so on. To start with cancel out the first letter.
As shown below for COREJAVA, first C is cancelled since it is the first letter, then J is cancelled since it is fourth letter (3 (value of C) + 1) from C, followed by R which is 11th letter (10 (value of J) + 1) from J and so on.
Note: Do not count already cancelled characters while moving.
Input (Character array) | Output (Character) |
---|---|
['C', 'O', 'R', 'E', 'J', 'A', 'V', 'A'] | *OREJAVA // Always Cancel First Character |
['D', 'O', 'T', 'N', 'E', 'T'] | E |
['H', 'I', 'B', 'E', 'R', 'N', 'A', 'T', 'E'] | E |
['P', 'E', 'R', 'L'] | E |
['D', 'A', 'B', 'C'] | *ABC // Cancel First Character D |
class FindRemainingLetterAfterStrikingOut2
{ public static void main(String s[])
{
char input[] = {'C', 'O', 'R', 'E', 'J', 'A', 'V', 'A'};
System.out.println("The remaining letter is : " + getRemainingLetter(input));
}
public static char getRemainingLetter(char[] input) {
//Write code here to get the remaining letter after striking out as explained above.
}
}
Topic: Learn Arrays And Loops