{
public static void initials(String S)
{
int[]A=new int[S.length()];
int sp=0;
for(int i=0; i
A[sp++]=i;
if(sp==0)
System.out.println(S);
else
{
System.out.print(S.charAt(0)+". ");
for(int i=0; i
System.out.print(S.charAt(A[i]+1)+". ");
System.out.print(S.substring(S.lastIndexOf(' ')+1, S.length()));
}
}
}
Sir,
ReplyDeletefor loops are incomplete and syntax errors are arising while compiling the program.
I'm really sorry mate.
DeleteWill get it fixed as soon as possible.
Your response helped in improving the quality.
Thank you. :)
Here is your Program
ReplyDeleteimport java.util.*;
public class nameinitial
{
public static void main(String args[])
{
// variable to read the string
String fullname;
//scanner class to get the user input
Scanner s1=new Scanner(System.in);
System.out.println("Enter your first middle and last name separted using single
space");
fullname=s1.nextLine();
//splitting the given name on the basis of spaces
String[] parts=fullname.split(" ");
// storing 1st character in a character variable
char f=parts[0].charAt(0);
// storing 2nd character in a character variable
char m=parts[1].charAt(0);
//concatinating the initials and . and last name
System.out.println(f + "." + m + "." + parts[2]);
}
}
hey can you do this without arrays and split please?
DeleteI run the program
DeleteThere was an error : could not find the main class
can't u do this program using BufferdReader insted of scannr clss.
ReplyDeleteCan you program in Java to print initials of name in capitals and leaving the last name as same. for example
ReplyDeleteMohandas karmchand ganDhi
Output shown is --- > M. K. Gandhi