试编写一个将摄氏温度转换为华氏温度的程序,其转换公式如下:
华氏温度=(9/5)*摄氏温度+32
/**
* 〈一句话功能简述〉<br>
* 〈摄氏温度转换为华氏温度,转换公式:华氏温度=(9/5)*摄氏温度+32〉
*
* @author Zhangnuanxin
* @create 2020/9/22
* @since 1.0.0
*/
import java.util.Scanner;
/**
* 采用Scanner类中的方法
* 优点一: 可以获取键盘输入的字符串
* 优点二: 有现成的获取int,float等类型数据,非常强大,也非常方便;
*/
public class Homework1_3 {
public static void main(String[] args)
{
float Fahrenheitdegree, Celsiusdegree;
//采用float类型,定义Fahrenheitdegree(华氏度)和Celsiusdegree(摄氏度)两个变量
Scanner scan = new Scanner(System.in);
//初始化一个Scanner类对象scan,便于后期输入摄氏度
System.out.print("Please enter a Celsius degree: ");
Celsiusdegree = scan.nextFloat();
//给出提示并输入一个摄氏度
Fahrenheitdegree = (9.0f / 5.0f) * Celsiusdegree + 32;
//转换公式:华氏温度=(9/5)*摄氏温度+32
System.out.println("The Celsiusdegree is transformed to the Fahrenheitdegree,the answer is "+Fahrenheitdegree);
//输出转换结果
}
}