This strategy is often used. A prototype for a system will be built using a language that is particularly
suited to rapid development, thus leading quickly to working code for testing. When the concept
has been proved, the algorithms can be rewritten in a language particularly suited for high
performance and scalability.
190 ANSWERS TO REVIEW QUESTIONS
PROGRAMMING IN JAVA
5.1 Write a Java program that divides the number 74.3 by 12.6 and reports the result of the division. Store
the dividend and divisor in variables named dividend and divisor before performing the division. What
will be the type of these variables? What will be the type of the result? What is the quotient?
public class Divide {
//A Java program that divides the number 74.3
// by 12.6 and reports the result
public static void main( String[] args ) {
double dividend = 74.3;
double divisor = 12.6;
double result = dividend / divisor;
System.out.println( "Result: 74.3 / 12.6 = " + result);
}
}
Result: 74.3 / 12.6 = 5.896825396825397
5.2 Write a Java program to compute the area of a circle whose radius is 5. For the value of PI, use 3.14.
Now rewrite your program so that it uses the very precise value of PI available as a static constant in the
Math class that comes with Java.
Pages:
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509