4.1. Numeric Output
To anyone working in the environment of a modern high-level language, the idea of calling a subroutine without first understanding the details of its internal operation should hardly be unfamiliar. In the case of library functions, you to do it all the time. For example, to set y to the square root of x in Java, you unhesitatingly write
y = Math.sqrt(x);
because you already have a good sense of what the sqrt function in the Math class does—it calculates square roots. At the same time, you probably have no clue as to how it does it. There are many possible algorithms for computing square roots. Some implementations may compute a power-series expansion; others might use Newton's method or even reduce the square root problem to its equivalent expression in terms of logarithms and exponentials. In any case, most users have little concern for such details.
As another example, let's suppose that n is an integer. To display the decimal representation of n in the context of a ConsoleProgram, all you need to do in Java is invoke the print method, as follows:
print(n);
In writing Java programs, you have used such statements freely, without worrying about the internal details. In point of fact, this operation is considerably more complicated than it appears.
The reason that printing a number is complicated arises from the fact that most systems are not capable of printing numeric values directly. Instead, any number must first be converted into the appropriate sequence ...
Get Thinking Recursively with Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.