Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TempConverter {
  4.  
  5. public static void main(String[] args) {
  6. boolean inUse = true;
  7. Scanner in = new Scanner(System.in);
  8.  
  9. while(inUse) {
  10. System.out.println("----------- Temperature Converter -----------");
  11. System.out.println("\tCelsius to Fahrenheit: Type 1");
  12. System.out.println("\tFahrenheit to Celsius: Type 2");
  13.  
  14. int conversionType = in.nextInt();
  15.  
  16. if(conversionType == 1) {
  17. System.out.println("Celsius to Fahrenheit mode.");
  18. }
  19. else if(conversionType == 2) {
  20. System.out.println("Fahrenheit to Celsius mode.");
  21. }
  22.  
  23. System.out.print("What temperature do you want to convert? ");
  24. double temp = in.nextDouble();
  25.  
  26. double output;
  27. if(conversionType == 1) {
  28. output = (9.0/5 * temp) + 32;
  29. System.out.println(temp + "°C = " + output + "°F");
  30. }
  31. else if(conversionType == 2) {
  32. output = (temp - 32) * 5/9.0;
  33. System.out.println(temp + "°F = " + output + "°C");
  34. }
  35.  
  36.  
  37. System.out.println("Do you want to convert a different temperature? (y/n)");
  38. String userCont = in.next();
  39. if(userCont.equals("yes") || userCont.equals("y")) {
  40. inUse = true;
  41. }
  42. else if(userCont.equals("no") || userCont.equals("n")) {
  43. inUse = false;
  44. }
  45.  
  46. }
  47.  
  48. in.close();
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement