Computer Science, asked by Ashwani1111, 1 year ago

how to find the intials of an entered string and print the last name...for ex Mohandas Karamchand Gandhi to M.K.Gandhi..in JAVA

Answers

Answered by Reba000
4
I'll give you the program. U can ask me if u hv any doubts in it.

import java.io.*;
import java.util.*;
class name
{

public static Scanner obj=new Scanner(System.in);
public static void main(String args[])throws IOException
{
String name;
int i,len,ctr=1;
char y;
System out.print("enter name");
name=obj.nextLine();
len=name.length();
System.out.print(name.substring(0)+"."); //Prints the 1st letter and a dot
for(i=0;i{
y=name.charAt(i);
if(y==""&&ctr==1)
{
System.out.print(((char)i+1)+".");
ctr++
}
elseif(y==""&&ctr==2)
System.out.print(name.substring(i+1));
}}
}


Similar questions