exercise2_1.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 23 行

JAVA
23
字号
import javax.swing.JOptionPane;

public class Exercise2_1  {
  // Main method
  public static void main(String[] args) {
    // Enter a temperatur in Fahrenheit
    String fahrenheitString = JOptionPane.showInputDialog(null, 
      "Enter a temperature in fahrenheit:",
      "Exercise2_1 Input", JOptionPane.QUESTION_MESSAGE);

    // Convert string to double
    double fahrenheit =  Double.parseDouble(fahrenheitString);
    
    // Convert it to Celsius
    double celsius = (5.0 / 9.0) * (fahrenheit - 32);

    // Display the result
    System.out.println("The temperature is " +
      celsius + " in Celsius");

    System.exit(0);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?