
1) WAP in java to accept the full name of a person and output must be only initials followed by the surname ant the short form.

import java.util.*;
public class PrintInitials {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Input Name: ");
String str = input.nextLine();
String st[] = str.split(" ");
char ch[] = new char[st.length - 1];
for (int i = 0; i < st.length - 1; i++) {
ch[i] = st[i].charAt(0);
}
int len = st.length;
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i] + ".");
}
System.out.print(st[len - 1]);
}
}

import java.util.*;
public class PrintInitials {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter Name");
String name=input.nextLine();
input.close();
int index = name.lastIndexOf( " " ) + 1;
String st= name.substring(0,index);
Scanner scan=new Scanner(st);
while(scan.hasNext()){
System.out.print(scan.next().charAt(0)+".");
}
scan.close();
System.out.print(name.substring(index));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.