×
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
29267    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.
Leo Tolstoy
However diffcult life may seem, there is always something you can do, and succeed at. It matters that you don not just give up.
Leo Tolstoy
589
80.53
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54058
25/06/2018     45077
01/01/2018     43640
28/06/2017     41178
02/08/2017     40183
01/08/2017     34225
06/07/2017     34027
15/05/2017     33271
11/09/2018     30256
14/07/2017     29789
softetechnologies