Unformatted text preview: The problem is that n1, n2, n3 are integers of int type, and 3 is also an integer. Your answer will be stored as an integer with decimal digits truncated. Try the following methods to correct this problem: a. Typecast the total you summed : System.out.println( (double) (n1 + n2 + n3) / 3); b. System.out.println( (n1 + n2 + n3) / 3 . ); // notice the period after the 3. Why does this work? c. Try to create a variable to hold the sum and a double type variable to hold the average of the three numbers: a. double sum = n1 + n2 + n3; b. double ave = sum / 3; d. Will the following statement produce accurate answer to the 2 nd decimal digit? double ave = (n1 + n2 + n3) / 3;...
View
Full
Document
This note was uploaded on 01/20/2010 for the course MATH 107 taught by Professor Christinashow during the Spring '08 term at Mesa CC.
 Spring '08
 ChristinaShow

Click to edit the document details