import java.io.* ;
public class LinearSearch
{
public static void main(String[] args) throws Exception
{
int[] Adata = new int[] {9, 3, 45, 4, 15, 4, 10, 23, 84} ;
for (int i=0 ; i System.out.println(" 第 " + (i+1) + " 個數--> " + Adata[i]);
BufferedReader br=new BufferedReader
(new InputStreamReader(System.in)) ;
System.out.print(" 請輸入要搜尋的數字: ") ;
int searchNum = Integer.parseInt(br.readLine());
int num = -1 ;
for (int j=0 ; j {
if (Adata[j] == searchNum)
num = j ;
}
System.out.println("================");
if (num == -1)
System.out.println(" 沒有這個數字--> " + searchNum) ;
else
System.out.println(" " + searchNum + " 是第 " + (num+1) + " 個數。") ;
}
}
arrow
arrow
    全站熱搜

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