Java Reference
In-Depth Information
// Requires:
//
Keyin class in current directory
import java.lang.*;
strictfp class Logs
{
public static void main(String[] args)
{
double num, loge, log10, aloge, alog10;
// Obtain input from user
num = Keyin.inDouble(“Enter number: ”);
// Calculate and display the natural logarithm
loge = Math.log(num);
System.out.println(“log basee=”+loge);
// Calculate the common log
log10 = Math.log(num)/Math.log(10.0);
System.out.println(“log base 10=”+log10);
// Calculate the antilogarithm of log base e
aloge = Math.exp(loge);
System.out.println(“antilog of log basee=”+aloge);
// Calculate the antilogarithm of log base 10
alog10 = Math.pow(10.0, log10);
System.out.println(“anitlog of log base 10=”+alog10);
}
}
On the Web
The program named Logs.java is found in the Chapter 23 folder at
www.crcpress.com .
Random Numbers
In computer games and in scientific and engineering simulations it is some-
times necessary to obtain a number,or set of numbers,at random. Com
-
puters can be programmed to generate random numbers; however,their
values may repeat after a certain number of iterations. It has been proven
that true randomness requires mechanical devices. For this reason comput-
ers are often said to produce pseudo-random numbers. However,these
pseudo-random numbers are often of sufficient quality to be useful in many
applications.
Java provides several mechanisms for obtaining random numbers. The
class java.util.Random contains ten methods that relate to the generation
Search WWH ::




Custom Search