wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes problem with variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with variable" Watch "problem with variable" New topic

problem with variable

Dominic Griffin

Joined: Jun 10, 2009
Posts: 16
I am trying to calculate occupancy the occupancy rate of an hotel. The expression is returning a zero. Does anyone see an obvious solution?

Henry Wong

Joined: Sep 28, 2004
Posts: 18495

The variables on the right are ints, so when you do the division, it will truncate the non-integer portion. The variable that you are assigning to is also an int, and hence, can't hold the non-integer portion.

It may be a good idea to cast to floating point before doing the division -- and assign it to a floating point variable.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
In other words, your program has only two possibilities. Hotel is full, or hotel is empty.
Dominic Griffin

Joined: Jun 10, 2009
Posts: 16
The lightbulb just clicked. It all makes sense now. Thank you gentlemen!
Consider Paul's rocket mass heater.
subject: problem with variable
Similar Threads
Help with assigning Array Size
Cannot throw exception
Input Validation Help
I keep having a issue with variables and methods.
try...catch blocks giving <identifier> expected error