Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package conversions;
  2.  
  3. import javax.swing.JOptionPane;
  4. public class FtoC {
  5. public static void main(String [] args){
  6. String input1;
  7. double celsiustoconvert = 0, fahrenheittoconvert = 0;
  8. double result = 0;
  9. String option;
  10. {
  11. option = JOptionPane.showInputDialog("Please select 1 for celsius to fahrenheit, or 2 for fahrenheit to celsius");
  12. if(option.matches("1")){
  13. input1 = JOptionPane.showInputDialog("Enter a temperature: ");
  14. celsiustoconvert = Double.parseDouble(input1);
  15.  
  16. result = ((celsiustoconvert * 9/5)+32);
  17. System.out.println(result + " fahrenheit");
  18. }else if (option.matches("2")){
  19. input1 = JOptionPane.showInputDialog("Enter a temperature: ");
  20. fahrenheittoconvert = Double.parseDouble(input1);
  21.  
  22. result = ((fahrenheittoconvert - 32) * 5/9);
  23. System.out.println(result + " celsius");
  24. }while(true);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement