tempconverter.java

来自「Java Server Pages Examples code JavaSer」· Java 代码 · 共 28 行

JAVA
28
字号
package com.ora.jsp.util;

/**
 * This class contains a couple of static methods for converting 
 * between Fahrenheit and Celsius. The methods are mapped to
 * el functions in the book examples TLD file.
 *
 * @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
 * @version 1.0
 */
public class TempConverter {
    /**
     * Main method to test the other methods.
     */
    public static void main (String[] args) throws Exception {
        System.out.println("20 C is " + toFahrenheit(20) + " F");
        System.out.println("68 F is " + toCelsius(68) + " C");
    }
    
    public static double toCelsius(double fahrenheit) {
        return (fahrenheit - 32) * 5 / 9;
    }

    public static double toFahrenheit(double celsius) {
        return celsius * 9 / 5 + 32;
    }
}

⌨️ 快捷键说明

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