Login Register


Convert to Celsius using Methods filter_list
Author
Message
Convert to Celsius using Methods #1
So can anyone convert Celsius using loops and methods? Here are some specific instructions:

Celsius Temperature Table

Where F is the Fahrenheit temperature and C is the Celsius temperature. Write a method named Celsius that accepts a Fahrenheit temperature as an argument. The method should return the temperature, converted to Celsius. Demonstrate the method by calling it in a loop that displays a table of the Fahrenheit temperature 0 to 20 and their Celsius equivalents.

I started you off can you finish and modify?

Code:
public class conversiontable { public static void main(String [] args) { System.out.println("The following is a table that converts Celsius to Fahrenheit:"); System.out.println("Celsius Fahrenheit"); for (int c= 0; c <= 20; c= c+1) { int convertf= (c*9/5)+32; int f= convertf; System.out.println(+c+" "+f); } } } /* The following is a table that converts Celsius to Fahrenheit: Celsius Fahrenheit 0 32 1 33 2 35 3 37 4 39 5 41 6 42 7 44 8 46 9 48 10 50 11 51 12 53 13 55 14 57 15 59 16 60 17 62 18 64 19 66 20 68 */
[Image: hB771xr.png?1?5086]

Reply

RE: Convert to Celsius using Methods #2
dont know if i understood well !! what u did here already converts from f to c from 0 to 20 !! so u did the job if i understood well u need a method to convert ?

Reply

RE: Convert to Celsius using Methods #3
i think that's what u've asked for:
Code:
package conversiontable; public class Conversiontable { public static int convert(int c) { int f = (c * 9 / 5) + 32; return f; } public static void main(String[] args) { System.out.println("The following is a table that converts Celsius to Fahrenheit:"); System.out.println("Celsius Fahrenheit"); for (int c = 0; c <= 20; c = c + 1) { System.out.println(c + " " + convert(c)); } } }

Reply







Users browsing this thread: