write a program in java to enter a String and frame a word by joining all the write a program in Java to enter a string and frame a word by joining all the first characters of each word. Display the new world
Answers
Answered by
73
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);
}
}
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