⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binarysearchapp.java

📁 Binary Search in Java. This can read in a .txt file and do search,sort on the file and output the so
💻 JAVA
字号:
//------------------------------------------------------------------------------//Programmer:	Jun Cui //Date:         08.05.2008//Assignment:   IT214 Java Lab 6 //Software:     Netbeans IDE 6.0//------------------------------------------------------------------------------package pbinarysearch;import java.io.*;/** * * @author CUIJ2 */public class BinarySearchApp {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        String[] testNumbers = {"sky","water","sun","flower"};//array to sort        String wanted = "sun";        BinarySearch test = new BinarySearch();       // BinarySearch test1 = new BinarySearch();              System.out.print("Here is the unsorted small array:\n");        for (int i = 0;i<testNumbers.length;i++)        {            System.out.print(testNumbers[i]+", ");        }                       test.selectSort(testNumbers);        System.out.println("\nHere is the sorted small array:");        for (int i = 0;i<testNumbers.length;i++)        {            System.out.print(testNumbers[i]+", ");        }                System.out.println("\nSearching for " +wanted+ " in the small array");        System.out.println(test.search(testNumbers, wanted));        //----------Sort the threebears.txt file and Print to little.txt file-----------                int num = 1290;        String[] newArray = new String[num];        int index = 0;        String want = "y";        BufferedReader in;        BinarySearch worker1  = new BinarySearch();                String line;        try        {            in =new BufferedReader(new FileReader("threebears.txt"));            while (((line = in.readLine())!= null)&&(index < num))            {                newArray[index] = line;                index++;            }        }        catch(IOException e)        {            System.out.println("There was a problem with the file");            e.printStackTrace();        }        catch(NumberFormatException ne)        {            System.out.println("Not a number: the string did not " +                    "convert to a number ");            ne.printStackTrace();        }                System.out.print("\nSort the threebears.txt file successfully!");        worker1.selectSort(newArray);                System.out.println("\n\nSearching for " +want+                 " in the sortedBears.txt file");        System.out.println(worker1.search(newArray, want));         //-----Write the sorted numbers into sortedBears.txt file for comparision------               try        {            FileWriter outFile = new FileWriter("sortedBears.txt");            PrintWriter out = new PrintWriter(outFile);                        for(int i = 0; i < newArray.length; i++)                out.println(newArray[i]);                        out.close();        }        catch (IOException e)        {            e.printStackTrace();                    }                System.out.print("\nWrite the sorted threebears.txt file to " +                "sortedBears.txt successfully!");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -