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 introcs-data.zip.


1 ELEMENTS OF PROGRAMMING DATA
1.1.1 HelloWorld.java Hello, World
1.1.2 UseArgument.java using a command-line argument
1.2.1 Ruler.java string concatenation example
1.2.2 IntOps.java integer multiplication and division
1.2.3 Quadratic.java quadratic formula
1.2.4 LeapYear.java leap year
1.2.5 RandomInt.java casting to get a random integer
1.3.1 Flip.java flippling a fair coin
1.3.2 TenHellos.java your first while loop
1.3.3 PowersOfTwo.java computing powers of two
1.3.4 DivisorPattern.java your first nested loops
1.3.5 Harmonic.java harmonic numbers
1.3.6 Sqrt.java Newton's method
1.3.7 Binary.java converting to binary
1.3.8 Gambler.java gambler's ruin simulation
1.3.9 Factors.java factoring integers
1.4.1 Sample.java sampling without replacement
1.4.2 CouponCollector.java coupon collector simulation
1.4.3 PrimeSieve.java sieve of Eratosthenes
1.4.4 SelfAvoidingWalk.java self-avoiding random walks
1.5.1 RandomSeq.java generating a random sequence
1.5.2 TwentyQuestions.java interactive user input
1.5.3 Average.java averaging a stream of numbers
1.5.4 RangeFilter.java a simple filter
1.5.5 PlotFilter.java input-to-drawing filter USA.txt  
1.5.6 BouncingBall.java bouncing ball
1.5.7 PlayThatTune.java digital signal processing elise.txt  Ascale.txt  StairwayToHeaven.txt  
1.6.1 Transition.java computing the transition matrix tiny.txt  medium.txt  
1.6.2 RandomSurfer.java simulating a random surfer
1.6.3 Markov.java mixing a Markov chain
2 FUNCTIONS DATA
2.1.1 Newton.java Newton's method (revisited)
2.1.2 Gaussian.java Gaussian functions
2.1.3 Coupon.java coupon collector (revisited)
2.1.4 PlayThatTuneDeluxe.java play that tune (revisited) elise.txt  Ascale.txt  StairwayToHeaven.txt  
2.2.1 StdRandom.java random number library
2.2.2 StdArrayIO.java array I/O library
2.2.3 IFS.java iterated function systems sierpinski.txt  barnsley.txt  tree.txt  coral.txt  
2.2.4 StdStats.java data analysis library
2.2.5 StdStats.java data analysis library
2.2.6 Bernoulli.java Bernoulli trials
2.3.1 Euclid.java Euclid's algorithm
2.3.2 TowersOfHanoi.java towers of Hanoi
2.3.3 Beckett.java Gray code
2.3.4 Htree.java recursive graphics
2.3.5 Brownian.java Brownian bridge
2.4.1 Percolation.java percolation scaffolding testEZ.txt  test5.txt  test8.txt  
2.4.2 VerticalPercolation.java vertical percolation testEZ.txt  test5.txt  test8.txt  
2.4.3 Visualize.java percolation visualization client
2.4.4 Estimate.java percolation probability estimate
2.4.5 Percolation.java percolation detection testEZ.txt  test5.txt  test8.txt  
2.4.6 PercPlot.java adaptive plot client
3 OBJECT ORIENTED PROGRAMMING DATA
3.1.1 ChargeClient.java charged particles
3.1.2 AlbersSquares.java Albers squares
3.1.3 Luminance.java luminance library
3.1.4 Grayscale.java converting color to grayscale mandrill.jpg  darwin.jpg  
3.1.5 Scale.java image scaling mandrill.jpg  
3.1.6 Fade.java fade effect mandrill.jpg  darwin.jpg  
3.1.7 Potential.java visualizing electric potential charges.txt  
3.1.8 GeneFind.java finding genes in a genome genomeTiny.txt  genomeVirus.txt  
3.1.9 Cat.java concatenating files in1.txt  in2.txt  
3.1.10 StockQuote.java screen scraping for stock quotes
3.1.11 Split.java splitting a file DJIA.csv  
3.2.1 Charge.java charged-particle data type
3.2.2 Stopwatch.java stopwatch data type
3.2.3 Histogram.java histogram data type
3.2.4 Turtle.java turtle graphics data type
3.2.5 Spiral.java Spira mirabilis
3.2.6 Complex.java complex number data type
3.2.7 Mandelbrot.java Mandelbrot set
3.2.8 StockAccount.java stock account data type Turing.txt  
3.3.1 Complex.java Complex numbers (revisited)
3.3.2 Counter.java counter data type
3.3.3 Vector.java spatial vector data type
3.3.4 Document.java document data type genomeA.txt  
3.3.5 CompareAll.java Similarity detection Constitution.txt  TomSawyer.txt  HuckFinn.txt  Prejudice.txt  Picture.java  DJIA.csv  Amazon.html  ACTG.txt  
3.4.1 Body.java gravitational body data type
3.4.2 Universe.java N-body simulation 2body.txt  3body.txt  4body.txt  2bodyTiny.txt  
4 DATA STRUCTURES DATA
4.1.1 ThreeSum.java 3-sum problem 8ints.txt  1Kints.txt  4Kints.txt  8Kints.txt  
4.1.2 DoublingTest.java validating a doubling hypothesis
4.2.1 TwentyQuestions.java binary search (20 questions)
4.2.2 Gaussian.java bisection search (function inversion)
4.2.3 BinarySearch.java binary search (sorted array) test.txt  whitelist.txt  
4.2.4 Insertion.java insertion sort tiny.txt  TomSawyer.txt  
4.2.5 InsertionTest.java doubling test for insertion sort
4.2.6 Merge.java mergesort tiny.txt  
4.2.7 FrequencyCount.java frequency counts Leipzig100K.txt  
4.2.8 LRS.java longest repeated substring genome15.txt  genomeTiny.txt  
4.3.1 ArrayStackOfStrings.java stack of strings (array) tobe.txt  
4.3.2 LinkedStackOfStrings.java stack of strings (linked list) tobe.txt  
4.3.3 DoublingStackOfStrings.java stack of strings (array doubling) tobe.txt  
4.3.4 Stack.java stack data type tobe.txt  
4.3.5 Evaluate.java expression evaluation
4.3.6 Queue.java queue data type tobe.txt  
4.3.7 MD1Queue.java M/D/1 queue simulation
4.3.8 LoadBalance.java load balancing simulation
4.4.1 Lookup.java dictionary lookup amino.csv  DJIA.csv  ip.csv  
4.4.2 Index.java indexing TaleOfTwoCities.txt  
4.4.3 BST.java BST symbol table data type
4.4.4 DeDup.java dedup filter TaleOfTwoCities.txt  
ST.java symbol table data type
SET.java set data type
4.5.1 Graph.java graph data type tiny.txt  
4.5.2 IndexGraph.java using a graph to invert an index tiny.txt  movies.txt  amino.csv  
4.5.3 PathFinder.java shortest-paths client routes.txt  movies.txt  
4.5.4 PathFinder.java shortest-paths implementation routes.txt  movies.txt  
4.5.5 SmallWorld.java small-world test moviesG.txt  
GraphGenerator.java graph generator



Exercise solutions.

Here is a list of solutions to selected coding exercises.


1 ELEMENTS OF PROGRAMMING
1.1.1 TenHelloWorlds.java ten Hello, Worlds
1.1.5 UseThree.java three command-line arguments
1.2.20 SumOfTwoDice.java sum of two dice
1.2.23 SpringSeason.java is month and day in Spring?
1.2.25 WindChill.java compute wind chill factor
1.2.26 CartesianToPolar.java Cartesian to polar coordinates
1.2.29 DayOfWeek.java compute day of week from date
1.2.30 Stats5.java average, min, max of 5 random numbers
1.2.34 ThreeSort.java sort three integers
1.2.35 Dragon.java dragon curve of order 5
1.3.8 FivePerLine.java print integers five per line
1.3.11 FunctionGrowth.java table of functions
1.3.12 DigitReverser.java reverse digits
1.3.13 Fibonacci.java Fibonacci numbers
1.3.15 SeriesSum.java convergent sum
1.3.20 BinaryToString.java binary number to string conversion
1.3.31 Ramanujan.java taxicab numbers
1.3.32 ISBN.java ISBN checksum
1.3.38 Sin.java sine function via Taylor series
1.3.41 MonteHall.java Monte Hall problem
1.4.2 HugeArray.java creating a huge array
1.4.10 Deal.java deal poker hands
1.4.13 Transpose.java tranpose a square matrix
1.4.25 InversePermutation.java compute inverse permutation
1.4.26 Hadamard.java compute Hadamard matrix
1.4.30 Minesweeper.java create Minesweeper board
1.4.33 RandomWalkers.java N random walkers
1.4.35 Birthdays.java birthday problem
1.4.37 BinomialCoefficients.java binomial coefficients
1.5.1 MaxMin.java max and min from standard input
1.5.3 Stats.java mean and stddev from standard input
1.5.5 LongestRun.java longest consecutive run from stdin
1.5.11 WordCount.java word count from standard input
1.5.15 Closest.java closest point
1.5.18 CheckerBoard.java draw a checkerboard
1.5.21 Rose.java draw a rose
1.5.22 Banner.java animate a text banner
1.5.31 Spirograph.java draw spirograph
1.5.32 Clock.java animate a clock
1.5.33 Oscilloscope.java simulate an oscilloscope
2 FUNCTIONS
2.1.4 ArrayEquals.java are two integer arrays equal?
2.1.30 BlackScholes.java Black-Scholes option valuation
2.1.32 Horner.java Horner's method to evaluate a polynomial
2.1.33 Benford.java Benford's law
2.1.38 Calendar.java create a calendar
2.2.1 Gaussian.java overloaded gaussian distribution functions
2.2.2 Hyperbolic.java hyperbolic trig functions
2.2.4 StdRandom.java shuffle an array of doubles
2.2.6 StdArrayIO.java array IO methods
2.2.11 Matrix.java matrix operations
2.2.12 MarkovSquaring.java page rank via matrix squaring
2.2.14 StdRandom.java exponential random variable
2.3.14 AnimatedHtree.java animated H-tree
2.3.15 IntegerToBinary.java integer to binary conversion
2.3.17 Permutations.java all permutations
2.3.18 PermutationsK.java all permutations of size k
2.3.19 Combinations.java all combinations
2.3.20 CombinationsK.java all combinations of size k
2.3.22 RecursiveSquares.java recursive squares
2.3.24 GrayCode.java Gray code
2.3.26 AnimatedHanoi.java animated Towers of Hanoi
2.3.29 Collatz.java Collatz function
2.3.30 BrownianIsland.java Brownian island
2.3.31 PlasmaCloud.java plama cloud
2.3.32 McCarthy.java McCarthy's 91 function
2.3.33 Tree.java fractal tree
2.4.15 PercolationDirectedNonrecursive.java directed percolation