import [Link].
Scanner;
class Decode {
private String word; // to store the encoded word
private int length; // to store length of the encoded word
private String new_word; // to store the decoded word
// Default constructor
Decode() {
word = "";
new_word = "";
length = 0;
}
// Method to accept the encoded word
void acceptWord() {
Scanner sc = new Scanner([Link]);
[Link]("Enter the encoded word: ");
word = [Link]().toLowerCase(); // convert to lowercase
length = [Link]();
}
// Method to decode the word
void findWord() {
new_word = "";
int i = 0;
while (i < length) {
char ch = [Link](i);
int expectedCount = (ch - 'a') + 1; // a=1, b=2, c=3, ...
int count = 0;
int j = i;
// Count how many times current character repeats
while (j < length && [Link](j) == ch) {
count++;
j++;
}
// If count matches the expected frequency, it’s a valid letter
if (count == expectedCount) {
new_word += ch;
i = j; // Move to next group of letters
} else {
// Skip invalid group (in case of malformed input)
i++;
}
}
}
// Method to display both the encoded and decoded words
void Display() {
[Link]("Encoded Word : " + word);
[Link]("Decoded Word : " + new_word);
}
// Main function to run the program
public static void main(String[] args) {
Decode obj = new Decode(); // create object
[Link](); // input
[Link](); // process
[Link](); // output
}
}