This Program Prints Name Initials.
For ex . Input => mohammad xyzabc alamOutput =>M.X. ALAM
----------------------------------------------------PROGRAM------------------------------------
import java.util.Scanner;
public class LaastNmae {
public static void main(String []argv)
{
int d=0,space=0;
String a;
Scanner br=new Scanner(System.in);
System.out.println("Enter the name =>");
a=br.nextLine();
System.out.print("\nName initials : ");
for( int i=0;i<a.length();i++)
{
if(a.charAt(i)==' ')
{
space=i+1;
System.out.print(a.toUpperCase().charAt(d)+".");
d=i+1;
}
}
for( int i=space;i<a.length();i++)
{
System.out.print(a.toUpperCase().charAt(i));
}
br.close();
}
}
No comments:
Post a Comment