java convert char to string .charAt(). Java logic programming question with answer.
-Given 2 strings, a and b, return a new string made of the first char of a and the last char of b, so "yo" and "java" yields "ya". If either string is length 0, use '@' for its missing char.lastChars("last", "chars") → "ls"
lastChars("yo", "java") → "ya"
lastChars("hi", "") → "h@"
Solution :
public String lastChars(String a, String b) {
String n;
int l2= a.length();
int l3= b.length();
char co,ct;
if (l2 == 0)
co ='@';
else
co = a.charAt(0);
if(l3==0)
ct='@';
else
ct = b.charAt(l3-1);
String p1= Character.toString(co);
String p2= Character.toString(ct);
n=p1+p2;
return n;
}
******* Like us in FB & get more updates ... Like
0 comments:
Post a Comment