要求假如輸入"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);
??????? }
?}
?