Skip to content

Instantly share code, notes, and snippets.

@thetekst
Created August 3, 2012 12:57
Show Gist options
  • Save thetekst/3247450 to your computer and use it in GitHub Desktop.
Save thetekst/3247450 to your computer and use it in GitHub Desktop.
Converter(F/C)
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