簡(jiǎn)單的實(shí)現(xiàn)卻不會(huì)
要求假如輸入"asdf as df as" 則輸出字符串之中最長(zhǎng)字符串,
如果兩個(gè)同時(shí)最長(zhǎng)如"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(" ");//-------〉將字符串按照空格拆分成字符串?dāng)?shù)祖
??????????? int max = 0;
??????????? String ss = "";
??????????? for (int i = 0; i < s.length; i++) { //-----s.length為拆分的叔組長(zhǎng)度
??????????????? if (max < s[i].length()) {//---------s[i].length()為單個(gè)數(shù)組字符串長(zhǎng)度
??????????????????? max = s[i].length();
??????????????? }
??????????? }
??????????? for (int i = 0; i < s.length; i++) {
??????????????? if (max == s[i].length()) {
??????????????????? ss += s[i] + "|";
??????????????? }
??????????? }
??????????? System.out.println(ss);
??????? }
?}
?
posted on 2007-01-03 22:33 youngturk 閱讀(225) 評(píng)論(2) 編輯 收藏 所屬分類: 個(gè)人隨筆總結(jié)