I wrote this simple program a while back but it doesn't quite work properly.
For some reason the surname is repeated. Any ideas?
I was gonna study this for an upcoming test but since its faulty then there is no point in studying something wrong!PHP Code:class StringTest
{
public static void main(String[] args)
{
String str1 = new String();
String str2 = new String();
char initial=' ', firstletsn;
int i=0, start=0, end=0, endstr;
System.out.print("Enter your firstname followed by your surname ");
str1 = EasyIn.getString();
endstr = str1.length();
while (i < endstr)
{
System.out.println(str1.charAt(i)+ " " + i);
i++;
}
i=0;
while(str1.charAt(i)== ' ')
i++;
start=i;
initial = str1.charAt(start);
str1 = str1.toLowerCase();
while ((str1.charAt(i)>='a')&&(str1.charAt(i)<='z'))
i++;
while(i < endstr)
{
System.out.println(str1.charAt (i) + " " + i);
i++;
}
end = i;
str2 = str1.substring(start,end);
firstletsn = str2.charAt(start);
str2 = str2.toUpperCase();
firstletsn = str2.charAt(0);
str2 = str2.substring(1,str2.length());
str2 = str2.toLowerCase();
System.out.println(firstletsn+str2 + " " + initial + ".");
}
}



Adv Reply





Bookmarks