發問區
會員登入 新使用者?立即註冊 . 服務首頁|服務說明|Yahoo!奇摩.知識+ 首頁 知識分類 電腦網路 科學常識 醫療保健 煩惱心事 生活資訊 手機通訊 休閒嗜好 視聽娛樂 運動體育 社會人文 商業金融 教育學習 .如何做 煩惱 主題知識 .我要發問 發表 我要發問 ..熱門: 牙齒變黃 咖啡過量 A型流感 隔夜菜有害? 不合星座 主題 金蛇報喜,大過好年 用手機上知識+ .知識搜尋 ....知識+ 首頁> 電腦網路> 程式設計> Java 加入追蹤 轉寄朋友 友善列印 .知識問題| Search Array Value. 發問者: 小羽 ( 初學者 5 級) 發問時間: 2009-10-05 04:01:23 解決時間: 2009-10-06 05:11:00 解答贈點: 22 ( 共有 1 人贊助 ) 回答: 2 評論: 0 意見: 0 [ 檢舉 ] 網友正面評價 100% .共有 4 人評價.create program to search for certain value in an array a) create an array of string type that contains 10 names b) use a loo(either for or while) to search through the array for the name specified by the user c) when the name is found, terminate the loop right away pseudo-ocode - when you find... please enter a name to search in my database: Eric Looking for "Eric"... Not at index 0... Not at index 1... Bingo! I found "Eric" at index 6!! Search ends pseudo-ocode - when you cannot find... please enter a name to search in my database: Eric Looking for "Linda"... Not at index 0... Not at index 1... Sorry! "Linda" is not in my database!! Search ends 拜託個位大大幫幫我阿.. 我想了好多天都想不出來阿..~“~ 在這邊先謝謝大家了..感激不近.. 最佳解答發問者自選 .. 回答者: ωετμοφντ ( 知識長 ) 擅長領域: 英文 | Java 回答時間: 2009-10-05 12:06:42 [ 檢舉 ] .請參考我的做法 public static void main(String[] args) { // 10 names array String[] ary = {"James", "John", "Robert", "Michael", "William", "Mary", "Patricia", "Linda", "Barbara", "Elizabeth"}; // user input System.out.print("Please enter a name to search in my database: "); Scanner scan = new Scanner(System.in); String s = scan.next(); System.out.println("Looking for " + s + "..."); boolean found = false; // flag for name found for (int i = 0; i < ary.length; i++) { if (s.equals(ary[i])) { System.out.println("Bingo! I found \"" + s + "\" at index " + i + "!!"); found = true; // set the name found to true break; // once found, break the loop } } if (!found) { System.out.println("Sorry! \"" + s + "\" is not in my database!!"); } } 相關詞: eric clapton,神話eric,eric dane,eric johnson,eric bana,eric winter,eric gagne,eric mabius,eric martin,eric lively Eric,an array,string type,Array,please enter a name,Bingo,a name,database,Scanner scan,ary[ 快速連結 ] 其它回答( 1 ) | 意見( 0 ) | 評論( 0 ) .發問者評價 大家的都很好..:) 但是他的我看得比較懂阿.. 不好意思... 謝謝大家阿.. .發表你的評價 你的評價 發表評價: 正面 普通 負面 評價內容: 發表 取消 . 加入追蹤 轉寄朋友 友善列印 .馬上按讚 加入 Yahoo! 奇摩 知識+ 粉絲團 •免費下載空姐英文教戰手冊 •多益700分線上測驗題庫 •解析奧斯卡電影背後的秘密 相關問答 [ 韓劇 ]請問有人知道文政赫(Eric)與韓智慧演的韓劇名稱是? . [ 西洋音樂 ]請問喜歡 Eric Clapton 的人,我要做報告.... . [ 韓國藝人 ]神話的Eric演過哪些戲? . [ 韓國藝人 ]請問~~~Eric 有啥作品(電視劇)?? . [ 偶像劇 ]波塞冬eric . [ 歐美藝人 ]Eric Saade資料瑞典 . 更多 .其他回答(1) 意見(0) 相關評論(0) . 001 回答者: sosad ( 初學者 5 級 ) 回答時間: 2009-10-05 11:19:55 [ 檢舉 ] ..import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SearchArray { private static String[] nameArray; static { nameArray = new String[] { "Amelia", "Fish", "Carlos", "Janus", "Evan", "Scout", "Alex", "Kevin", "Chasefor" }; } /** * @param args */ public static void main(String[] args) { System.out.print("please enter a name to search in my database: "); BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in)); try { String str = bfr.readLine(); int index = doSearch(str); if (index == -1) { System.out.println("Sorry! \"" + str + "\" is not in my database!!"); } else { System.out.println("Bingo! I found \"" + str + "\" at index " + index); } System.out.println("Search ends"); } catch (IOException e) { e.printStackTrace(); } } private static int doSearch(String pName) { System.out.println("Looking for \"" + pName + "\""); for (int i=0; i

arrow
arrow
    創作者介紹
    創作者 phibrain201 的頭像
    phibrain201

    youtube收尋

    phibrainno1 發表在 痞客邦 留言(0) 人氣()


    留言列表 留言列表

    發表留言