Write Small Code Segment Ask User Phrase Make Acronym Code Ask Phrase Enter Hardcore Phras Q37124850

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 PowerShell PS D: Chegg java Acronym> javac AcronymDemo.java PS D:Cheggjava Acronym> java AcronymDemo Enter a phras

Windows

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.