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());
}
}
Step-by-step 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.