×
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
29148    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
Pure mathematics is, in its way, the poetry of logical ideas.
Albert Einstein
1562
79.52
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     53841
25/06/2018     44920
01/01/2018     43498
28/06/2017     41069
02/08/2017     40047
01/08/2017     34093
06/07/2017     33922
15/05/2017     33173
11/09/2018     29932
14/07/2017     29629
softetechnologies