1.1.3
Command-line method of taking arguments:
1.stdin.readint (): Java XX, run, input parameters, separated by spaces or line breaks;
2.integer.parseint (Args[0]): Java XX parameter, separated by a space, run.
1.1.6
for (int i = 0; I <=; i++) { stdout.println (f); = f + g; = f- g;}
Note that when running to G = f-g, this line, F has changed.
1.1.8
System.out.println (' B ' + ' C ');
Answer: 197
"" Represents a string, ' ' represents a char.
1.1.15
// Https://github.com/aistrate/AlgorithmsSedgewick Public Static int[] Histogram (int[] A,intM) { int[] h =New int[M]; intN =a.length; for(inti = 0; i < N; i++) if(A[i] <M) H[a[i]]++; returnh;}
Understanding test instructions, cleverly solved, do not have to write double loops.
1.1.19 *
// Https://github.com/aistrate/AlgorithmsSedgewick Public Static LongFib (intN) { Long[] f =New Long[N+1]; returnFib (N, f);} Public Static LongFib (intNLong[] f) { if(F[n] = = 0) { if(N = = 1) F[n]= 1; Else if(N > 1) F[n]= Fib (N-1, F) + fib (N-2, F); } returnf[n];}
Use an array to save the calculated values to better implement F (N).
The measurement proves that the original method output to more than 40 minutes, and the back is more and more slow (according to test instructions 1 hours are not all output), the improved method is almost the second output. Performance varies enormously.
Algorithm (4th edition)-1.1 exercises (partial)