Jump to content

why doesn't my calculator work? - JAVA

Go to solution Solved by shadow_ray,
4 hours ago, hirusha.adikari said:

and why cant i keep this a double with the getText

Double.parseDouble(str)

 

also get in the habit of using ( ) where convenient. 

 

For example  :

 

result = 9/5*hirusha+32   

 

Will give the right value in the result variable, because  division and multiplication have the same priority if my Java knowledge is accurate, so they'll be processed left to right , 9 / 5 and then the result multiplied by hirusha variable ... but for clarity it would be best to write  (9/5) * hirusha + 5  - this way any reader instantly knows the result of the fraction is multiplied, and you definitely didn't mean   9 / ( 5 * hirusha) 

 

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×