Ask Question
10 October, 11:16

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.

+2
Answers (1)
  1. 10 October, 14:18
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers