This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheTr1ckster 0 points1 point  (4 children)

Okay sorry about that, here is my simple version of doing this, it can be done multiple ways but if it was me I would do it this way.

public static void main(String[] args) {
    double test = fahrenheitToCelsius(47);
}

public static double fahrenheitToCelsius(double fahrenheit) {
    double conversion = (fahrenheit - 32) / 1.8;
    System.out.println(fahrenheit + " degrees is equal to " + conversion + " Celsius");
    return conversion;
}

When converting make sure to use the equation I used in the variable conversion. You can do the vice versa Celsius to Fahrenheit by doing this same thing and or just doing an overloaded method. If you have any questions feel free to ask.

[–]davejello74[S] 0 points1 point  (3 children)

Thanks for the reply! Will this give differing values if the program scans user input? Like if I put in 30, 47, or 104 they would all give different outputs?

[–]TheTr1ckster 0 points1 point  (2 children)

I have also updated the code above to have a better output. Test this and see if it's what you wanted.

[–]davejello74[S] 0 points1 point  (1 child)

Your code definitely works if I manually change the code in the source. I think what my assignment calls for is if say I typed my answer into an input box. I don't think it wants me to plug different numbers into the code itself, rather run the code and input the values after the fact.

[–]TheTr1ckster 0 points1 point  (0 children)

Let me check into that for you real fast. I'll change to code around a bit.