Ask Question
5 July, 00:21

g 6.8 LAB: Acronyms An acronym is a word formed from the initial letters of words in a set phrase. Write a program whose input is a phrase and whose output is an acronym of the input. If a word begins with a lower case letter, don't include that letter in the acronym. Assume there will be at least one upper case letter in the input.

+4
Answers (1)
  1. 5 July, 03:58
    0
    import java. util. Scanner;

    public class Acronym {

    public static String buildAcronym (String phrase) {

    String[] separatedWords = phrase. split (" ");

    String acronymAlphabets = "";

    for (int i = 0; i < separatedWords. length; + +i) {

    if (Character. isUpperCase (separatedWords [i]. charAt (0))) {

    acronymAlphabets + = Character. toUpperCase (separatedWords [i]. charAt (0));

    }

    }

    return acronymAlphabets;

    }

    public static void main (String[] args) {

    Scanner userInput = new Scanner (System. in);

    System. out. println (buildAcronym (userInput. nextLine ()));

    }

    }

    Explanation:

    Create a buildAcronym method inside the Acronym class that takes a phrase entered by user as an argument from the main method. Break down the phrase into separate words by using the built-in split function. Loop through the separated word and check if the current selected character is a capital alphabet and then add that alphabet to acronymAlphabets variable and return it. In the main method, get the phrase as an input from user. Finally call the buildAcronym method and display the result.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “g 6.8 LAB: Acronyms An acronym is a word formed from the initial letters of words in a set phrase. Write a program whose input is a phrase ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers