• Post Reply Bookmark Topic Watch Topic
  • New Topic

printf is giving exceptions and not printing the 3 decimals after  RSS feed

 
aaron butcher
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use "%.3f" as a first parameter.
And this will still not work as T is an integer. Declare T as double.
Also, 5/8*(n - 50) will always evaluate to 0.
 
aaron butcher
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Use "%.3f" as a first parameter.
And this will still not work as T is an integer. Declare T as double.
Also, 5/8*(n - 50) will always evaluate to 0.


how do i write the equation correctly.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5.0 / 8.0 * (n - 1)

5 / 8 is integer division (5 / 8 = 0)
5.0 / 8.0 is floating point division (5.0 / 8.0 = 0.625)
 
aaron butcher
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that makes perfect sense thanks I read in the instructions wrong and tried to do an int.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lots of people do that. Don't worry about it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!