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


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz