2012年3月20日 星期二

jAG303

import java.io.*;
import java.lang.*;
public class MyAG303 {
   public static void main(String[] args) throws Exception{
     BufferedReader in =
   new BufferedReader(new InputStreamReader(System.in));
     int a[]=
   {2,3,25,7,11,10,5,1,18,13,21,15,25,31,28,36,17,8,19,30};
     int key;
     boolean found=false;
     System.out.println( "請輸入要搜尋的整數:" );
     key=Integer.parseInt(in.readLine());
     for ( int i=0;i<a.length;i++ )  {
           if (a[i]==key)
               System.out.println( "要尋找的值是陣列的第" + i+"個元素" );
                 found=true;
          }
      if (!found)
           System.out.println( "找不到要尋找的值" );
     }
}

當輸入的值找不到時,沒有輸出?? 你找得到嗎??

No Response to "jAG303"

張貼留言