×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
WAP in java to accept a number (0 -999) and print it in words. Write a programme in java to accept a number and print the sum of its prime digits.
Accept a name and print only the initials with surname. - Java
22562    Arnab De    09/06/2018

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.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.

WAP in java to accept a number (0 -999) and print it in words. Write a programme in java to accept a number and print the sum of its prime digits.
softetechnologies
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.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
Education is the manifestationof the perfection already in man.
Swami Vivekananda
180
59.22
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44273
01/01/2018     36695
25/06/2018     36199
28/06/2017     34735
02/08/2017     33284
01/08/2017     27699
06/07/2017     27446
15/05/2017     27056
14/07/2017     22750
11/09/2018     21388
softetechnologies