registernativeexample.java

来自「< Professional Java,JDK 5 Edition>」· Java 代码 · 共 38 行

JAVA
38
字号
import java.io.*;

public class RegisterNativeExample {
    public native boolean sortNumbers(int strList[]);
    public native void setSort(int whichSort);

    static {
        System.loadLibrary("RegisterNativeLibrary");
    }

    public static void main(String args[])
    {
        RegisterNativeExample rne = new RegisterNativeExample();
        int sortType = 1;
        int nums[] = {23, 1, 6, 1, 2, 7, 3, 4};

        try {
            BufferedReader br = new BufferedReader(
                                          new InputStreamReader(System.in));

            System.out.println("Choose a sort routine");
            System.out.println("   1. Bubble");
            System.out.println("   2. Insertion");
            System.out.print("% ");
            sortType = Integer.parseInt(br.readLine());
            rne.setSort(sortType);
            rne.sortNumbers(nums);
            System.out.print("Sorted numbers are: ");
            for(int i=0; i<nums.length; i++) {
                System.out.print(nums[i] + " ");
            }
            System.out.println("");
        } catch(IOException ioe) {
            System.out.println("IOException occurred");
            ioe.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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