Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /**
  2. * Write a description of class guessingGame here.
  3. *
  4. * @Arjun Bhamra
  5. * @9/6/19
  6. */
  7. import java.util.*;
  8.  
  9. public class TempConverter
  10. {
  11.  
  12. public static void main(String args[]){
  13. tempConvert();
  14. Scanner kb = new Scanner(System.in);
  15. System.out.println("Press 1 to convert another temp, Press 2 if not");
  16. int choice = 1;
  17. while(choice==1){
  18.  
  19. choice=kb.nextInt();
  20. if(choice==1){
  21. tempConvert();
  22. choice=0;
  23. } else if(choice==2){
  24. System.out.println("Thank you for using this converter!");
  25. }
  26. }
  27. }
  28.  
  29. public static void tempConvert(){
  30. //Entering a temperature to convert
  31. Scanner scan = new Scanner(System.in);
  32. System.out.println("Please enter a temperature: ");
  33. int temp = scan.nextInt();
  34.  
  35. //Whether to convert from Celcius to Fahrenheit or vice versa.
  36. Scanner sc = new Scanner(System.in);
  37. System.out.println("C->F is 1, F->C is 2");
  38. int conversion = sc.nextInt();
  39. if(conversion==1 || conversion==2){
  40. if(conversion==1){
  41. double x=((9.0/5*temp)+32);
  42. System.out.println(temp + " degrees Celcius is " + (int)x + " degrees Fahrenheit");
  43. } else if(conversion==2){
  44. double y=(temp-32)*5/9.0;
  45. System.out.println(temp + " degrees Fahrenheit is " + (int)y + " degrees Celcius");
  46. }
  47. } else {
  48. System.out.println("You inputted something incorrect! Try again.");
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement