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


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad