223k views
0 votes
9.17 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.

1 Answer

4 votes

Answer:

Hence the code is given as follows,

import java.util.Scanner;

public class LabProgram {

public static String createAcronym(String userPhrase){

String result = "";

String splits[] = userPhrase.split(" ");

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

if(splits[i].charAt(0)>='A' && splits[i].charAt(0)<='Z')

result += splits[i].charAt(0);

}

return result;

}

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

String s = scan.nextLine();

System.out.println(createAcronym(s));

}

}

User Steve Meisner
by
5.3k points