初学java做了一个摄氏度转化华氏度的程序
37,47,57,67转化会出现多出好几位的现象,代码如下
import java.util.Scanner;
import java.awt.*;
import javax.swing.*;
public class 摄氏度转华氏度 {
public static void main(String[] args) {
System.out.print("欢迎使用华氏度转换器,");
Scanner sc = new Scanner(System.in);
System.out.print("请输入摄氏温度:");
double num1 = sc.nextInt();
double Celsius = num1;
int b = 32;
double a = 1.8;
double Fahrenheit = Celsius*a+b;
String str = "" + Fahrenheit;
System.out.println ("华氏度数为: " + Fahrenheit ); }
}
double num1 = sc.nextInt();
输入类型如果要是double类型那就是
double num1 = sc.nextDouble();
热门标签: