Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TemperatureConvert {
  4.  
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. String convert = "yes";
  8. while(convert.equals("yes")) {
  9. int ans;
  10. System.out.println("Would you like to: \n 1) Convert Celcius to Fahrenheit \n 2) Convert Fahrenheit to Celcius");
  11. ans = sc.nextInt();
  12. if(ans!=1 && ans!=2) {
  13. System.out.println("Invalid option.");
  14.  
  15. }
  16. else if(ans == 1) {
  17. System.out.println("What (interger) temperature would you like to convert? (°C)");
  18. int Ctemp = sc.nextInt();
  19. double CtoF = ((9.0/5)*Ctemp)+32;
  20. System.out.println(Ctemp+"°C is "+CtoF+"°F");
  21. }
  22. else if(ans==2) {
  23. System.out.println("What (interger) temperature would you like to convert? (°F)");
  24. int Ftemp = sc.nextInt();
  25. double FtoC = (Ftemp-32)*(5.0/9);
  26. System.out.println(Ftemp+"°F is "+FtoC+"°C");
  27. }
  28.  
  29.  
  30. System.out.println("Convert again? (yes/no)");
  31. convert = sc.next();
  32.  
  33. }
  34.  
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement