Created
August 3, 2012 12:57
-
-
Save thetekst/3247450 to your computer and use it in GitHub Desktop.
Converter(F/C)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Converter.java-> | |
public class Converter { | |
public String convertTemp(int temperature, char convertTo){ | |
int result = 0; | |
char value; | |
if(convertTo == 'F'){ | |
value = 'C'; | |
result = (temperature * 9/5) + 32; | |
} else{ | |
value = 'F'; | |
result = (temperature - 32) * 5/9; | |
} | |
return String.format("%d%c = %d%c", temperature, value, result, convertTo); | |
} | |
} | |
DemoConverter.java-> | |
public class DemoConverter { | |
public static void main(String[] args) { | |
Converter conv = new Converter(); | |
System.out.println(conv.convertTemp(350, 'C')); | |
} | |
} | |
// Result: | |
350F = 176C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment