要求假如输入"asdf as df as" 则输出字符串之中最长字符串,
如果两个同时最长如"asdf as df as asdf" 则输出asdf|asdf
如果中间有as/tdf则什么也不输出。
public class Zifu {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "asdfa fasd sf asdfa";
if (str.indexOf("/") >= 0) {
System.out.println("format error !");
} else {
String s[] = str.split(" ");//-------〉将字符串按照空格拆分成字符串数祖
int max = 0;
String ss = "";
for (int i = 0; i < s.length; i++) { //-----s.length为拆分的叔组长度
if (max < s[i].length()) {//---------s[i].length()为单个数组字符串长度
max = s[i].length();
}
}
for (int i = 0; i < s.length; i++) {
if (max == s[i].length()) {
ss += s[i] + "|";
}
}
System.out.println(ss);
}
}