java-小数点位数控制

计算公式如下:
Centigrade=5*(Farenheit -32)/9

Centigrade=5(Farenheit32)/9,java实现计算摄氏度,并利用DecimalFormat保留摄氏度的两位小数并输出

package ldm;
import java.util.Scanner;
import java.text.DecimalFormat;
public class hello {

	public static void main(String[] args) {
		DecimalFormat df=new DecimalFormat();
		Scanner sc=new Scanner(System.in);
		double t=sc.nextDouble();
		double m=5*(t-32)/9;
		String s="0.00";
		df.applyPattern(s);
		System.out.print("If the Farenheit is "+t+"the Centigrade is "+df.format(m));
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41061455/article/details/80473546
今日推荐