Home > Back-end >  "Algorithm" StdIn exactly how to input it
"Algorithm" StdIn exactly how to input it

Time:09-20

Have a brother used algs4. Jar this library? Other StdOut, StdDraw can, StdIn always don't understand how to do?
 import edu. Princeton. Cs. Algs4. StdIn; 
The import edu. Princeton. Cs. Algs4. StdOut;


Public class business {
Public static void main (String args []) {

Double sum=0.0;
int cnt=0;
while (! StdIn. IsEmpty ()) {
The sum +=StdIn. ReadDouble ();
cnt++;
}
Double avg=sum/CNT;
StdOut. Printf (" business is % 5 f \ n ", avg);
}
}

For example, I now have so a program (the book is so written, StdIn is like the author about the standard input stream wrapper class), with the IDEA of running, how the console input?? Direct input and press enter to use, and I am the algs4. Directly to the jar like ordinary jars to the project, download online watch others said to configure the environment variables, and I didn't can with other methods, this is the StdIn will not use,, have a brother to give directions??

CodePudding user response:

This watch his function should be able to guess

Directly to judge his return value try StdIn. ReadDouble ()

CodePudding user response:

End of the building Lord, is Ctrl + z (Windows), Ctrl + d (Linux), after the console input also not line, sometimes need to check it out, and then into the console press the key, if that's ok

CodePudding user response:


The file content is the content of the input, pay attention to the space
  • Related