Linear Search (Function)
Submit solution
Points:
50
Time limit:
1.0s
Memory limit:
10M
Authors:
Problem type
Allowed languages
Java 19
Description
請設計一個 Java 程式,在主程式 main 中建立以下已排序的字元陣列:{'a', 'c', 'm', 'n', 'p', 'q', 's', 't', 'v', 'w', 'x', 'y', 'z'}
程式需提示使用者輸入一個字元,並使用 Linear Search 且必須使用 method 實作 進行搜尋。
Requirements
- 請先在
main外部設定一class叫做SearchUtils SearchUtils實作一個 Linear Search 的 method,例如:linearSearch(char[] arr, char target)- 搜尋過程中需計算搜尋次數 ,且每進入一次比較算一次
++ - 若找到該字元,輸出:
- 該字元在陣列中的 index (從 0 開始)
- 搜尋次數
- 若找不到該字元,輸出:
Not found- 搜尋次數
Input / Output
| Sample 1 | Sample 2 | Sample 3 | |
|---|---|---|---|
| Input | p |
b |
a |
| Output | Position: 4Search count: 5 |
Not foundSearch count: 13 |
Position: 0Search count: 1 |
Comments