
How to print initials of a name without using arrays?

Hi Friend,
You can try the following code:
import java.util.*;
public class InitialName {
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));
}
}
Thanks

iwant with out public static void main

how to do it without using index of and last index of functions ????????
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.