Java Programs in the Textbook

Standard libraries.

Here are the standard input and output libraries that we use throughout the textbook.

Programs in the textbook.

Below is a table of the Java programs in the textbook. Click on the program name to access the Java code; click on the reference number for a brief description; read the textbook for a full discussion. You can download all of the programs as introcs.jar and the data as

1.1.1 Hello, World
1.1.2 using a command-line argument
1.2.1 string concatenation example
1.2.2 integer multiplication and division
1.2.3 quadratic formula
1.2.4 leap year
1.2.5 casting to get a random integer
1.3.1 flippling a fair coin
1.3.2 your first while loop
1.3.3 computing powers of two
1.3.4 your first nested loops
1.3.5 harmonic numbers
1.3.6 Newton's method
1.3.7 converting to binary
1.3.8 gambler's ruin simulation
1.3.9 factoring integers
1.4.1 sampling without replacement
1.4.2 coupon collector simulation
1.4.3 sieve of Eratosthenes
1.4.4 self-avoiding random walks
1.5.1 generating a random sequence
1.5.2 interactive user input
1.5.3 averaging a stream of numbers
1.5.4 a simple filter
1.5.5 input-to-drawing filter USA.txt  
1.5.6 bouncing ball
1.5.7 digital signal processing elise.txt  Ascale.txt  StairwayToHeaven.txt  
1.6.1 computing the transition matrix tiny.txt  medium.txt  
1.6.2 simulating a random surfer
1.6.3 mixing a Markov chain
2.1.1 Newton's method (revisited)
2.1.2 Gaussian functions
2.1.3 coupon collector (revisited)
2.1.4 play that tune (revisited) elise.txt  Ascale.txt  StairwayToHeaven.txt  
2.2.1 random number library
2.2.2 array I/O library
2.2.3 iterated function systems sierpinski.txt  barnsley.txt  tree.txt  coral.txt  
2.2.4 data analysis library
2.2.5 data analysis library
2.2.6 Bernoulli trials
2.3.1 Euclid's algorithm
2.3.2 towers of Hanoi
2.3.3 Gray code
2.3.4 recursive graphics
2.3.5 Brownian bridge
2.4.1 percolation scaffolding testEZ.txt  test5.txt  test8.txt  
2.4.2 vertical percolation testEZ.txt  test5.txt  test8.txt  
2.4.3 percolation visualization client
2.4.4 percolation probability estimate
2.4.5 percolation detection testEZ.txt  test5.txt  test8.txt  
2.4.6 adaptive plot client
3.1.1 charged particles
3.1.2 Albers squares
3.1.3 luminance library
3.1.4 converting color to grayscale mandrill.jpg  darwin.jpg  
3.1.5 image scaling mandrill.jpg  
3.1.6 fade effect mandrill.jpg  darwin.jpg  
3.1.7 visualizing electric potential charges.txt  
3.1.8 finding genes in a genome genomeTiny.txt  genomeVirus.txt  
3.1.9 concatenating files in1.txt  in2.txt  
3.1.10 screen scraping for stock quotes
3.1.11 splitting a file DJIA.csv  
3.2.1 charged-particle data type
3.2.2 stopwatch data type
3.2.3 histogram data type
3.2.4 turtle graphics data type
3.2.5 Spira mirabilis
3.2.6 complex number data type
3.2.7 Mandelbrot set
3.2.8 stock account data type Turing.txt  
3.3.1 Complex numbers (revisited)
3.3.2 counter data type
3.3.3 spatial vector data type
3.3.4 document data type genomeA.txt  
3.3.5 Similarity detection Constitution.txt  TomSawyer.txt  HuckFinn.txt  Prejudice.txt  DJIA.csv  Amazon.html  ACTG.txt  
3.4.1 gravitational body data type
3.4.2 N-body simulation 2body.txt  3body.txt  4body.txt  2bodyTiny.txt  
4.1.1 3-sum problem 8ints.txt  1Kints.txt  4Kints.txt  8Kints.txt  
4.1.2 validating a doubling hypothesis
4.2.1 binary search (20 questions)
4.2.2 bisection search (function inversion)
4.2.3 binary search (sorted array) test.txt  whitelist.txt  
4.2.4 insertion sort tiny.txt  TomSawyer.txt  
4.2.5 doubling test for insertion sort
4.2.6 mergesort tiny.txt  
4.2.7 frequency counts Leipzig100K.txt  
4.2.8 longest repeated substring genome15.txt  genomeTiny.txt  
4.3.1 stack of strings (array) tobe.txt  
4.3.2 stack of strings (linked list) tobe.txt  
4.3.3 stack of strings (array doubling) tobe.txt  
4.3.4 stack data type tobe.txt  
4.3.5 expression evaluation
4.3.6 queue data type tobe.txt  
4.3.7 M/D/1 queue simulation
4.3.8 load balancing simulation
4.4.1 dictionary lookup amino.csv  DJIA.csv  ip.csv  
4.4.2 indexing TaleOfTwoCities.txt  
4.4.3 BST symbol table data type
4.4.4 dedup filter TaleOfTwoCities.txt symbol table data type set data type
4.5.1 graph data type tiny.txt  
4.5.2 using a graph to invert an index tiny.txt  movies.txt  amino.csv  
4.5.3 shortest-paths client routes.txt  movies.txt  
4.5.4 shortest-paths implementation routes.txt  movies.txt  
4.5.5 small-world test moviesG.txt graph generator

Exercise solutions.

Here is a list of solutions to selected coding exercises.

1.1.1 ten Hello, Worlds
1.1.5 three command-line arguments
1.2.20 sum of two dice
1.2.23 is month and day in Spring?
1.2.25 compute wind chill factor
1.2.26 Cartesian to polar coordinates
1.2.29 compute day of week from date
1.2.30 average, min, max of 5 random numbers
1.2.34 sort three integers
1.2.35 dragon curve of order 5
1.3.8 print integers five per line
1.3.11 table of functions
1.3.12 reverse digits
1.3.13 Fibonacci numbers
1.3.15 convergent sum
1.3.20 binary number to string conversion
1.3.31 taxicab numbers
1.3.32 ISBN checksum
1.3.38 sine function via Taylor series
1.3.41 Monte Hall problem
1.4.2 creating a huge array
1.4.10 deal poker hands
1.4.13 tranpose a square matrix
1.4.25 compute inverse permutation
1.4.26 compute Hadamard matrix
1.4.30 create Minesweeper board
1.4.33 N random walkers
1.4.35 birthday problem
1.4.37 binomial coefficients
1.5.1 max and min from standard input
1.5.3 mean and stddev from standard input
1.5.5 longest consecutive run from stdin
1.5.11 word count from standard input
1.5.15 closest point
1.5.18 draw a checkerboard
1.5.21 draw a rose
1.5.22 animate a text banner
1.5.31 draw spirograph
1.5.32 animate a clock
1.5.33 simulate an oscilloscope
2.1.4 are two integer arrays equal?
2.1.30 Black-Scholes option valuation
2.1.32 Horner's method to evaluate a polynomial
2.1.33 Benford's law
2.1.38 create a calendar
2.2.1 overloaded gaussian distribution functions
2.2.2 hyperbolic trig functions
2.2.4 shuffle an array of doubles
2.2.6 array IO methods
2.2.11 matrix operations
2.2.12 page rank via matrix squaring
2.2.14 exponential random variable
2.3.14 animated H-tree
2.3.15 integer to binary conversion
2.3.17 all permutations
2.3.18 all permutations of size k
2.3.19 all combinations
2.3.20 all combinations of size k
2.3.22 recursive squares
2.3.24 Gray code
2.3.26 animated Towers of Hanoi
2.3.29 Collatz function
2.3.30 Brownian island
2.3.31 plama cloud
2.3.32 McCarthy's 91 function
2.3.33 fractal tree
2.4.15 directed percolation