Thread: Integer Usage
View Single Post
  #5 (permalink)  
Old 01-23-2008, 06:43 AM
bluegreen7hi bluegreen7hi is offline
Member
 
Join Date: Nov 2007
Posts: 12
bluegreen7hi is on a distinguished road
Okay, I got everything working for that part. Now for this next part I need it to compute the average of the integers and display it in decimal form using casting. I'm really having a hard time grasping the whole concept of casting. I know that if a number will not go into another number evenly, because both numbers are integers, the result has to be an integer, and it is just the answer truncated to the nearest integer in the direction of 0. However, how would I go about converting the answer this program gives of "33" into the actual answer in decimal form?

Here is the code I have:
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) / 5); } public static void main(String[] args) { computeSum(); computeAverage(); } }
Reply With Quote