Welcome To The World Of Java

This site will teach you the basics of Java. It is not necessary to have any prior programming experience.

Java program to input name, middle name and surname of a person and print only the initials.

Somdeb Burman | 11:59:00 AM | 2 comments

Example.

Enter your name
Umesh Kumar Kushwaha
Initials are   U.K.K.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class InitialName {
 public static void main(String args[]) throws IOException {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter your name");
  String s = br.readLine(), s1 = "";
  s = " " + s;
  int len = s.length();
  char a;
  for (int i = 0; i < len; i++) {
   a = s.charAt(i);
   if (a == ' ') {
    s1 = s1 + s.charAt(i + 1) + ".";
   }
  }
  System.out.println("Initials are   " + s1);
 }
}

Output:
Enter your name
Umesh Kumar Kushwaha
Initials are   U.K.K.

Java Resources are available for Download from below

Category: , , , ,

2 comments:

  1. https://blogmepost.com/34915/Write-java-program-accept-full-display-initials-along-surname

    ReplyDelete