Accept a name and print only the initials with surname.
09-06-2018    10832 times
initials surname.

Write a programme in java to accept a name and print only the initials with surname.

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.out.print("Enter A String : ");
        String str=sc.nextLine();
        String res="";
        String []words=str.split(" ");
        int i;
            res += words[i].charAt(0) + ".";
        res +=words[i].charAt(0) + words[i].substring(1).toLowerCase() + ".";


Enter A String : mahanDas kAram chanD ganDHi

    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post