Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package conversions;
- import javax.swing.JOptionPane;
- public class FtoC {
- public static void main(String [] args){
- String input1;
- double celsiustoconvert = 0, fahrenheittoconvert = 0;
- double result = 0;
- String option;
- {
- option = JOptionPane.showInputDialog("Please select 1 for celsius to fahrenheit, or 2 for fahrenheit to celsius");
- if(option.matches("1")){
- input1 = JOptionPane.showInputDialog("Enter a temperature: ");
- celsiustoconvert = Double.parseDouble(input1);
- result = ((celsiustoconvert * 9/5)+32);
- System.out.println(result + " fahrenheit");
- }else if (option.matches("2")){
- input1 = JOptionPane.showInputDialog("Enter a temperature: ");
- fahrenheittoconvert = Double.parseDouble(input1);
- result = ((fahrenheittoconvert - 32) * 5/9);
- System.out.println(result + " celsius");
- }while(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement