×
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
29304    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.
Albert Einstein
It is the supreme art of the teacher to awaken joy in creative expression and knowledge.
Albert Einstein
2870
80.85
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54130
25/06/2018     45126
01/01/2018     43677
28/06/2017     41212
02/08/2017     40227
01/08/2017     34273
06/07/2017     34074
15/05/2017     33311
11/09/2018     30332
14/07/2017     29838
softetechnologies