Programming Examples
Java program to from a new word by extracting the first letter of each word in the entered sentence
Write a Java program to from a new word by extracting the first letter of each word in the entered sentence.
Solution
import java.util.*;
class FirstLetter
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter any String");
String s=sc.nextLine();
int len=s.length();
char a;
String s2="";
s2=s2+s.charAt(0);
for(int i=1; i<len; i++)
{
a=s.charAt(i);
if(a==' ')
{
s2=s2+(s.charAt(i+1));
}
}
System.out.println("The new word : "+s2);
}
}
Output