Check Name in List


Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

請設計一個 Java 程式:

  • 第一行輸入為一串以空格分隔的名字,作為名單,儲存在 ArrayList<String> 中。

  • 第二行輸入為一個查詢名字。

  • 程式將檢查該查詢名字是否存在於名單中。若存在,顯示該名字在列表中的索引;若不存在,顯示該名字不在列表中。

輸入

第一行:一串名字,以空格分隔,例如:John Mike Sarah Tom David

第二行:查詢名字,例如:Sarah

輸出

若查詢名字存在於名單中,輸出:[name] is at index X 若查詢名字不存在於名單中,輸出:[name] is not in the list.

範例輸入 #1

John Mike Sarah Tom David
Sarah

範例輸出 #1

Sarah is at index 2

範例輸入 #2

Amy Brian Cindy
Tom

範例輸出 #2

Tom is not in the list.

Comments

There are no comments at the moment.