Computer Applications

Write a program to accept a word and print the Symbolic of the accepted word.

Symbolic word is formed by extracting the characters from the first consonant, then add characters before the first consonant of the accepted word and end with "TR".

Example:
AIRWAYS Symbolic word is RWAYSAITR
BEAUTY Symbolic word is BEAUTYTR

Java

Java String Handling

3 Likes

Answer

import java.util.Scanner;

class SymbolicWord
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        String w, res;
        int i, pos = -1;

        System.out.print("Enter a word: ");
        w = sc.nextLine();
        int l = w.length();

        for(i = 0; i < l; i++)
        {
            char ch = Character.toUpperCase(w.charAt(i));
            if(!(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'))
            {
                pos = i;
                break;
            }
        }

        if(pos != -1)
            res = w.substring(pos) + w.substring(0, pos) + "TR";
        else
            res = w + "TR";

        System.out.println("Symbolic word: " + res);
    }
}

Output

Answered By

2 Likes


Related Questions