⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converttemperatures.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import java.io.*;   // needed for keyboard input
import java.text.*;  // needed for formatting
public class ConvertTemperatures
{
  public static void main(String[] args)
  throws java.io.IOException   // for keyboard input
  {
    int tempType;
    double temp, fahren, celsius;
    String s1;
      // set up format variable
    DecimalFormat num = new DecimalFormat(",###.00");
      // set up the basic input stream for keyboard entry
      // needed for conversion capabilities  
    InputStreamReader isr = new InputStreamReader(System.in);
      // needed to use ReadLine()
    BufferedReader br = new BufferedReader(isr);
    System.out.print("Enter the temperature to be converted: ");
    s1 = br.readLine();
    temp = Double.parseDouble(s1);
     
    System.out.println("Enter an 1 if the temperature is in Fahrenheit");
    System.out.print(" or a 2 if the temperature is in Celsius: ");
    s1 = br.readLine();    
    tempType = Integer.parseInt(s1);
    if (tempType == 1)
    {
      celsius = (5.0 / 9.0) * (temp - 32.0);
      System.out.println("\nThe equivalent Celsius temperature is "
                      + num.format(celsius));
    }
    else
    {
      fahren =  (9.0 / 5.0) * temp + 32.0;
      System.out.println("\nThe equivalent Fahrenheit temperature is "
                      + num.format(fahren));
    }
  }
}

⌨️ 快捷键说明

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