File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Printf and Equations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printf and Equations" Watch "Printf and Equations" New topic
Author

Printf and Equations

Elle de Vasquez
Greenhorn

Joined: Oct 08, 2012
Posts: 6
Help please!

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won , 0.35 0.65
------------------------------------------------

Q1 - Avg. Games Won - has a comma (,) after it...why?
Q2 - I want to use the equation for avgw1 and avgw2 (the part that's commented out), but it gives me 0.00 as answers for both columns. Did I do the math wrong? the formatting?

Help!

Thanks much!
Sylver
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Q1 : Because you're printing one ! Look closely.


[My Blog]
All roads lead to JavaRanch
Elle de Vasquez
Greenhorn

Joined: Oct 08, 2012
Posts: 6
Oh good god...I just saw it now that you've pointed it out >.< Thanks!

Anything for q2?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Q2 : you'll have to make one of the two operands a double, otherwise the result will be an int (check this link). Try to cast one of the operands.
Elle de Vasquez
Greenhorn

Joined: Oct 08, 2012
Posts: 6
Oh! Got it, thank you VERY much!!! <3

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won 0.35 0.65
------------------------------------------------
Got it to work making games won a double instead of just an int
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

In my opinion, it should be an int. You can't win part of a game (unless you count a tie as a half), so logically it makes sense for it to be an int.

What I would do is cast it during the computation:

double avgw1 = (float) gw1/gp1;
double avgw2 = (float) gw2/gp2;


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
 
subject: Printf and Equations