• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Variable assignment using expression does not work...  RSS feed

 
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My calculations are not working.  I keep getting the same results, no matter what numbers I put in to begin with.  Here's the code:



This gives me 0.0C and 273.15K every single time.

What's going on?  Thanks.
 
Master Rancher
Posts: 2918
100
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Thomas,

have you been told about integer division yet? Try

and notice the outcome. A simple remedy against this is for instance:
but there are other ways too.
 
Marshal
Posts: 60806
190
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall leave you to work out why you might also sort out that problem by removing one pair of () from each line.
 
Piet Souris
Master Rancher
Posts: 2918
100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, missed that. Well spotted!
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do the same arithmetic twice.Try and avoid C/F: try \u2193 \u2103 or \u2109. The Kelvin symbol \u212a looks indistinguishable from an ordinary K.
 
Piet Souris
Master Rancher
Posts: 2918
100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: (...)Try and avoid C/F: try \u2193 \u2103 or \u2109. The Kelvin symbol \u212a looks indistinguishable from an ordinary K.


I tried to use unicode characters a while ago in my reply, but to no vail: all I got was this '\uxxxx' literally.. Is it explained somewhere how to correctly  insert these chars? Couldn't find it.
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTML combination ℃ shows up as ℃.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:I tried to use unicode characters a while ago in my reply, but to no vail: all I got was this '\uxxxx' literally.



The Ranch uses UTF-8 as its encoding, so if you can type (or paste) a Unicode character in the reply box then that should be enough. But note that I said Unicode characters. You seem to be talking about Unicode escapes, which are only used in Java source code. Like Campbell said, if you can't type the character then HTML escapes are the way to do that. And furthermore if you want to discuss HTML escapes in the forum then you'll need to escape the & at the beginning of the HTML escape you want to discuss.
 
Thomas Mahoney
Greenhorn
Posts: 4
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, guys.  Thanks for all of your help.  You really saved this program.
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . you'll need to escape the & . . .

Do you mean like this:- & or & or && or &&&&&&&&&&&&&&&&&&&& ?
 
Piet Souris
Master Rancher
Posts: 2918
100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Thomas
You're welcome!

@Campbell and Paul
that was still hard... what on earth is 'escaping html'?
But finally I managed, and using the 'x' that I constantly overlooked helped as well! Indeed, me dummy, and for dummies like me: to get that Celsius symbol I had to type "& #x2103" (without the space), and to get "&#x2103" I had to type "& amp#x2103" (again without the space).

Thank you, guys!
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . & amp#x2103 . . .

Full instructions in my previous post. Remember it's &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . & amp#x2103 . . .

&‍amp;#x2103;

And I'm not saying how I got rid of the space!
 
Piet Souris
Master Rancher
Posts: 2918
100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...   hopefully that doesn't spoil my well deserved nightrest.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!