<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java 程序:線性搜索 > 原文: [https://beginnersbook.com/2014/04/java-program-for-linear-search-example/](https://beginnersbook.com/2014/04/java-program-for-linear-search-example/) #### 示例程序: 該程序使用[線性搜索算法](https://en.wikipedia.org/wiki/Linear_search),在用戶輸入的所有其他數字中找出數字。 ```java /* Program: Linear Search Example * Written by: Chaitanya from beginnersbook.com * Input: Number of elements, element's values, value to be searched * 輸出:Position of the number input by user among other numbers*/ import java.util.Scanner; class LinearSearchExample { public static void main(String args[]) { int counter, num, item, array[]; //To capture user input Scanner input = new Scanner(System.in); System.out.println("Enter number of elements:"); num = input.nextInt(); //Creating array to store the all the numbers array = new int[num]; System.out.println("Enter " + num + " integers"); //Loop to store each numbers in array for (counter = 0; counter < num; counter++) array[counter] = input.nextInt(); System.out.println("Enter the search value:"); item = input.nextInt(); for (counter = 0; counter < num; counter++) { if (array[counter] == item) { System.out.println(item+" is present at location "+(counter+1)); /*Item is found so to stop the search and to come out of the * loop use break statement.*/ break; } } if (counter == num) System.out.println(item + " doesn't exist in array."); } } ``` 輸出 1: ```java Enter number of elements: 6 Enter 6 integers 22 33 45 1 3 99 Enter the search value: 45 45 is present at location 3 ``` 輸出 2: ```java Enter number of elements: 4 Enter 4 integers 11 22 4 5 Enter the search value: 99 99 doesn't exist in array. ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看