Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Converter {
  4.  
  5. public static void main(String[] args) {
  6. Scanner keyboard = new Scanner(System.in);
  7.  
  8. System.out.println("Welcome to the Fahrenheit/Celsius Converter!");
  9. System.out
  10. .println("To convert, type in your temperature and the identify if you are using fahrenheit or celsius.");
  11. System.out.println("Example: 69F or 69C F = Fahrenheit C = Celsius");
  12.  
  13. String temperature;
  14. char f = 'f';
  15. char c = 'c';
  16. char C = 'C';
  17. double answer, temp;
  18.  
  19. temperature = keyboard.nextLine();
  20.  
  21. if (temperature.contains("C")) {
  22. temperature = temperature.replace(C, ' ');
  23. temp = Double.valueOf(temperature);
  24. answer = temp * 9 / 5 + 32;
  25. System.out.println("Poof! The temperature is " + answer + "F");
  26. } else {
  27.  
  28. if (temperature.contains("c")) {
  29. temperature = temperature.replace(c, ' ');
  30. temp = Double.valueOf(temperature);
  31. answer = temp * 9 / 5 + 32;
  32. System.out.println("Poof! The temperature is " + answer + "F");
  33. } else {
  34.  
  35. if (temperature.contains("F")) {
  36. temperature = temperature.replace(f, ' ');
  37. temp = Double.valueOf(temperature);
  38. answer = (temp - 30) * 5 / 9;
  39. System.out.println("Poof! The temperature is " + answer
  40. + "C");
  41. } else {
  42.  
  43. if (temperature.contains("f")) {
  44. temperature = temperature.replace(f, ' ');
  45. temp = Double.valueOf(temperature);
  46. answer = temp - 30 / 2;
  47. System.out.println("Poof! The temperature is " + answer
  48. + "C");
  49. } else {
  50. System.out
  51. .println("You entered the temperature wrong!");
  52. }
  53. }
  54. }
  55. }
  56. keyboard.close();
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement