I am given a String name say String s in below code. This String contains a phrase i.e. one or more words separated by single spaces. This program computes and return the acronym of this phrase.
import java.math.*;
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Initials {
public String getInitials(String s) {
String r = "";
for(String t:s.split("\\s+")){
r += t.charAt(0);
}
return r;
}
void p(Object... o) {
System.out.println(deepToString(o));
}
}
Example: "john fitzgerald kennedy"
Returns: "jfk"