Thread: Integer Usage
View Single Post
  #7 (permalink)  
Old 01-23-2008, 08:15 AM
bluegreen7hi bluegreen7hi is offline
Member
 
Join Date: Nov 2007
Posts: 12
bluegreen7hi is on a distinguished road
Well, here's what I came up with. For the average, instead of assigning double to each integer, I just divided by (double)5. Here it is:

Code:
public class Math { static int a = 53; static int b = 40; static int c = 36; static int d = 12; static int e = 27; public static void computeSum() { System.out.println("The Sum Is:"); System.out.println(a + b + c + d + e); } public static void computeAverage() { System.out.println("The Average Is:"); System.out.println((a + b + c + d + e) / (double)5); } public static void main(String[] args) { computeSum(); computeAverage(); } }
Compiles and runs perfectly, displaying the correct 33.6 as the average. Thanks for all your help.
Reply With Quote