Three-letter acronyms are common in the business world. For example, in Java you
ID: 3759011 • Letter: T
Question
Three-letter acronyms are common in the business world. For example, in Java you use the IDE (Integrated Development Environment) in the JDK (Java Development Kit) to write programs used by the JVM (Java Virtual Machine) that you might send over a LAN (local area network). Programmers even use the acronym TLA to stand for three-letter acronym. Write a program that allows a user to enter three words, and display the appropriate three-letter acronym in all uppercase letters. If the user enters more than three words, ignore the extra words. Save the file as ThreeLetterAcronym.java.
Explanation / Answer
import java.util.Scanner;
public class Acronym {
public static void main(String args[])
{
String[] words;
Scanner sc = new Scanner(System.in);
String text = sc.nextLine();
words = text.split("\s+");
for (int i = 0; i < words.length; i++) {
words[i] = words[i].replaceAll("[^\w]", "");
}
for (int i = 0; i < 3; i++) {
System.out.print(Character.toUpperCase(words[i].charAt(0)));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.