Nearly two days since the first entry, belonging to the familiar environment of the stage, the next algorithm (fourth edition), when not using the IDE tool directly using the terminal for Javac compiled with the package class, and then use Java will appear the following error prompt:
Using Google search for a long time, finally found a solution to make a record, lest it will forget
Because the problem occurs because the package path exists in the Binarysearch.java class, I use Eclipse to place the file in workspace.
Package com.sort;
Public classBinarySearch { Public Static intRankintKey,int[] a) { returnRank (key,a,0,a.length-1); } Public Static intRankintKey,int[] A,intLointhi) { //if key exists with a[], its index will not be less than lo and will not be greater than hi if(Lo>hi)return-1; intmid=lo+ (Hi-lo)/2; if(Key < A[mid])returnRank (key,a,lo,mid-1); Else if(Key>a[mid])returnRank (key,a,mid+1, HI); Else returnmid; } Public Static voidMain (string[] args) {int[] a={0,2,4,5,6,7,12,45}; intT=rank (1, a); System.out.println (t); //stdout.println ("Hello, World"); }}
The package path for this class should be com.sort
When the compilation is complete, the package name of the package still needs to be taken, both Com.sort.BinarySearch and because the edit file is under the sort package, which requires us to navigate to the COM package using a relative path.
Use the command JAVA-CP. /.. / Com.sort.BinarySearch
The command executed successfully.
Javac\java Class with package path