Thread: Integer Usage
View Single Post
  #8 (permalink)  
Old 01-23-2008, 08:19 AM
CaptainMorgan's Avatar
CaptainMorgan CaptainMorgan is offline
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by bluegreen7hi View Post
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.
Lol, yep, that works too. Congratulations, you've just hacked. What I said about up and down casting still holds.. which, from what I gather you might already have an idea about. As you've just proven, there's many ways to do one task, especially in Java and the route you take for that task can depend on any number of factors(design, taste, etc.).

Good job.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Reply With Quote