Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Metric{
  4. public static void main(String [] args){
  5.  
  6. Scanner input = new Scanner(System.in);
  7. double usernum;
  8. int selec;
  9.  
  10. System.out.println("What is the temperature of this room?");
  11.  
  12. usernum = input.nextDouble();
  13.  
  14. System.out.println("Press 1 to convert from C to F and 2 to convert from F to C");
  15.  
  16. selec = input.nextInt();
  17.  
  18. if(selec == 1)
  19. usernum = CtoF(usernum);
  20.  
  21. else if(selec == 2)
  22. usernum = FtoC(usernum);
  23.  
  24. else
  25. System.out.println("Bad input");
  26.  
  27. if(selec == 1 || selec == 2)
  28. System.out.println(usernum);
  29. }
  30.  
  31. public static double FtoC(double a){
  32. double constant = 5 / 9;
  33.  
  34. a = (a - 32) * constant;
  35.  
  36. return a;
  37. }
  38.  
  39. public static double CtoF(double a){
  40. double constant = 9 / 5;
  41.  
  42. a = a * constant + 32;
  43.  
  44. return a;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement