Ask Question
22 December, 17:19

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. 22 December, 17:45
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers