×
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
29481    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.
Rabindranath Tagore
A lamp can only light another lamp when it continues to burn in its own flame.
Rabindranath Tagore
4820
82.8
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54462
25/06/2018     45530
01/01/2018     43906
28/06/2017     41421
02/08/2017     40488
01/08/2017     34494
06/07/2017     34274
15/05/2017     33515
11/09/2018     30761
14/07/2017     30258
softetechnologies