This program will help you to print the initials of a name taken as input from the user.
Java Program :
import java.io.*;
class name_initials
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,d=0,space=0;
char k;
String a;
System.out.print("Enter the name : ");
a=br.readLine();
System.out.print("\nName initials : ");
for(i=0;i<a.length();i++)
{
k=a.charAt(i);
if(k==' ')
{
space=i+1;
System.out.print(a.charAt(d)+".");
d=i+1;
}
}
for(i=space;i<a.length();i++)
{
k=a.charAt(i);
System.out.print(k);
}
System.out.print("\n");
System.out.println("\nThank you for using this short program");
}
}
Java Program :
import java.io.*;
class name_initials
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,d=0,space=0;
char k;
String a;
System.out.print("Enter the name : ");
a=br.readLine();
System.out.print("\nName initials : ");
for(i=0;i<a.length();i++)
{
k=a.charAt(i);
if(k==' ')
{
space=i+1;
System.out.print(a.charAt(d)+".");
d=i+1;
}
}
for(i=space;i<a.length();i++)
{
k=a.charAt(i);
System.out.print(k);
}
System.out.print("\n");
System.out.println("\nThank you for using this short program");
}
}
EVEN THOUGH I MODIFIED THE PROGRAM USING SCANNER CLASS;
ReplyDeleteTHANKS A LOT !!!
This feature proves valuable in various applications, from database management to user interfaces, My Unwachable Stream enhancing efficiency and user experience through concise representation of individuals' names.
ReplyDelete