Write a program in Java to enter a String and frame a word by joining all characters of each word. Display a new word
Answers
Answered by
3
Explanation:
The program is:-
import java.util.*;
class Word
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence");
String s=sc.nextLine();
s=s+" ";
s=s.toUpperCase();
String s1="",s2="";
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch!=' ')
{
s1=s1+ch;
}
else
{
s2=s2+s1.charAt(0)+".";
s1="";
}
}
System.out.println("The short form is "+s2);
}
}
Similar questions