Computer Science, asked by everleigh, 8 months ago

write a Java program to accept a full name and display the initials along with the surname.

URGENT! give the full program please​

Answers

Answered by navylover2916
10

Answer:

import java.util.*;

public class hello  {

  public static void main(String[] args) {

   Scanner scan=new Scanner(System.in);

     

     System.out.println("Enter your full name");

     String name = scan.next();

     System.out.println("The full name is: " + name);

     System.out.print("Initials with surname is: ");

     int len = name.length();

     name = name.trim();

     String str1 = "";

     for (int i = 0; i < len; i++) {

        char ch = name.charAt(i);

        if (ch != ' ') {

           str1 = str1 + ch;

        } else {

           System.out.print(Character.toUpperCase(str1.charAt(0)) + ". ");

           str1 = "";

        }

     }

     String str2 = "";

     for (int j = 0; j < str1.length(); j++) {

        if (j == 0)

           str2 = str2 + Character.toUpperCase(str1.charAt(0));

        else

           str2 = str2 + Character.toLowerCase(str1.charAt(j));

     }

     System.out.println(str2);

  }

}

Similar questions