write a small code segment that will ask the user fora phrase and make it into an acronym.The code should ask for thephrase to enter (do not hardcore the phrase or the response).Anacronym will take the first letter of each word and put themtogether to make a new word. The acronym should be all uppercaseeven in the word in the phrase is not uppercase.
Code about ( string representation and message encoding)
Solution
import java.util.*;
class AcronymDemo
{
public static void main(String args[])
{
String phrase,acronym=””;
Scanner sc=new Scanner(System.in);
System.out.print(“nnEnter a phrase : “);
phrase=sc.nextLine();
String []words=phrase.split(” “);
for(String word:words)
{
acronym=acronym+word.charAt(0);
}
System.out.println(“nAcronym of given phrase is”+acronym.toUpperCase());
System.out.println(“n”);
}
}
Windows