最近用java写hdu11页,记一下东西

来源:互联网 发布:zarchiver解压数据错误 编辑:程序博客网 时间:2024/06/05 18:20

hdu2001,控制小数位数

import java.util.Scanner;import java.math.*;import java.text.DecimalFormat;public class j2001 {    public static void main(String[] args){        int x1,y1,x2,y2;        Scanner sc = new Scanner(System.in);        while(sc.hasNext()){            double x11 = sc.nextDouble();            double y11 = sc.nextDouble();            double x22 = sc.nextDouble();            double y22 = sc.nextDouble();            double ans = Math.sqrt((x11-x22)*(x11-x22)+(y11-y22)*(y11-y22));            DecimalFormat df = new DecimalFormat("#0.00");//控制小数位数两位            System.out.println(df.format(ans));        }    }}
原创粉丝点击