compile error: cannot find symbol: In, StdIn and StdOut
If you have already set up the environment recommended for the course, only add this lines to your java file
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
Classes StdIn
, StdOut
and In
aren't part of the standard Java libraries. They're support classes provided to go along with the Princeton course.
From the 1.1 Programming Model page linked in the source code:
Standard input and standard output.
StdIn.java
andStdOut.java
are libraries for reading in numbers and text from standard input and printing out numbers and text to standard output. Our versions have a simpler interface than the corresponding Java ones (and provide a few tecnical improvements)....
In.java
andOut.java
are object-oriented versions that support multiple input and output streams, including reading from a file or URL and writing to a file.
So if you want to use the binary search code as-is, you'll need to download those files.
You can replace then with
Output:
System.out.println(key);
Input
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String Key= null;
try {
Key = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
They are using custom libraries to print the value to console(Presumably) You can redirect the output to console.