Split the given sting by space (" ") character. and store into a string array. Now get the first character of each word, except last word, followed by a dot (.) character. Now print the last word by convert the first character into uppercase and others characters into lower case.
import java.util.*;
public class Initial
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter A String : ");
String str=sc.nextLine();
String res="";
str=str.toUpperCase();
String []words=str.split(" ");
int i;
for(i=0;i<words.length-1;i++)
{
res += words[i].charAt(0) + ".";
}
res +=words[i].charAt(0) + words[i].substring(1).toLowerCase() + ".";
System.out.println(res);
}
}
Output
Enter A String : mahanDas kAram chanD ganDHi
4M.K.C.Gandhi.