The function below takes one parameter: a string (full_name) consisting of words separated by whitespace. Make an acronym from the words by making a new word by selecting the first letter of each word, and then capitalizing the new word. For example, if given the string 'international business machines', your function would return 'IBM'.

To implement this, split the given string to get a list of strings (one string per word). Iterate through the words, building a string from the first letters of each word. Then convert the result to upper case letters using the upper() function.

Respuesta :

Answer:

The python program is given below

Explanation:

def make_acronym(full_name):

#initialize a local with empty string

  final=""

#split the word with spaces into list

  wordList=full_name.split()

#for loop the wordList list

  for word in wordList:

#convert the first character to upper case

#and add to local variable final

       final=final+ word[0].upper()

#return the abbreviation

  return final

#invoke the api using print function

print(make_acronym("international business machines"))

print(make_acronym("tamil nadu"))

print(make_acronym("indian legend"))

OUTPUT

IBM

TN

IL

Answer:

// Import Scanner class to allow program receive user input

import java.util.Scanner;

// Class definition

public class Solution {

   // Main method which begin program execution

   public static void main(String args[]) {

     // Scanner object scan is defined

     Scanner scan = new Scanner(System.in);

     // Prompt telling the user to enter a sentence

     System.out.println("Enter your sentence: ");

     //User input is assigned to userInput

     String userInput = scan.nextLine();

     //The userInput is split into Array and store with inputArray variable

     String[] inputArray = userInput.split(" ");

     //The outputed abbreviation

     String shortCode = "";

     //for loop to go through the inputArray

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

         //temporary variable to hold each array element

         String temp = inputArray[i];

         shortCode += temp.charAt(0);

     }

     // The shortcode is displayed in upper case

     System.out.println(shortCode.toUpperCase());

   }

}

Explanation:

The solution is implemented using Java.

First the Scanner class is imported to allow the program receive user input. Then inside  the main method, we declared a scanner object 'scan', then prompt the user to enter input.

The user input is assigned to 'userInput', then the input is splitted and assigned to 'inputArray'. A 'shortCode' variable is declared which hold the abbreviation.

Then a for-loop is use to go through the inputArray and concatenate the first letter of each word to shortCode.

The shortCode is displayed in upper case.