मराठी

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 - Computer Applications

Advertisements
Advertisements

प्रश्न

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

कोड लेखन
Advertisements

उत्तर

import java.util.Scanner;

public class SymbolicWord {
    public static String toSymbolic(String word) {
        String w = word;
        int n = w.length();
        String vowels = "AEIOUaeiou"; // Added lowercase for safety
        int firstConsonant = -1;

        // Find the position of the first consonant
        for (int i = 0; i < n; i++) {
            char c = w.charAt(i);
            if (Character.isLetter(c) && vowels.indexOf(c) == -1) {
                firstConsonant = i;
                break;
            }
        }

        // Apply the rules
        if (firstConsonant == -1) {
            return w + "TR";
        } else {
            String suffix = w.substring(firstConsonant);
            String prefix = w.substring(0, firstConsonant);
            return suffix + prefix + "TR";
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String s = sc.next();
        System.out.println("Symbolic word: " + toSymbolic(s));
        sc.close();
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×