• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Temperature conventor in main class

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys , i am trying to make a conventor of degree in main and i have a problem how to do this.
this the code that i have write so far i would love to have tips and ideas how to make it work.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jenia Levin wrote:



First of all: the "=" operator is for assigning a value to a variable. To compare two values you would use the comparison operator, which is "==". (Two equal signs, not one.)

Second of all: your c is a char variable, and you're trying to compare it to the String constant "F". To compare it to a char value you would use the char constant 'F'. (Single quotes, not double.)
 
Bartender
Posts: 242
27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

So the first thing I'd recommend is formatting your code. Any modern IDE will allow you to do that with one keypress. Specifically, it's pretty tough to read those if statements when they're formatted like that.

Second - please describe the issue you're having in detail when asking a question, since it'll help other people help you. Based on the code, I'm guessing the problem is that it says all the temperature readings are zero no matter what you enter.

For this line:

What data type is c?
What data type is "F"?
(edit) Paul beat me to it here. Yeah, these are not the same data type. I actually missed that it used "=" instead of "==", so it just won't even compile as it is now.

I strongly advise splitting up these lines:

Using && to connect multiple different statements may work (though I don't know if it does) but it's definitely not good style. It makes those lines much harder to read - and saving lines of code is never an advantage if it hurts readability. There's actually an issue with the line above, and if you split it up into multiple lines rather than using && between them, you'll likely be able to see what it is.
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jenia Levin wrote:



Did you mean for that to be two statements, which you would do the first one followed by the second one? If so, then in Java you separate statements by semicolons, not by double ampersands.

And the value of 5/9 is zero, that's how integer arithmetic works. There's no place for the remainder to go. You should use double values instead: 5.0/9.0.
 
reply
    Bookmark Topic Watch Topic
  • New Topic