简单算法两题

来源:互联网 发布:剑灵忽雷捏脸数据 编辑:程序博客网 时间:2024/05/21 18:43

   这几天在适应工作加上换住的地方就没有练习算法,接着来吧

ACM2001

package com.shiyu.acm.test;import java.math.BigDecimal;import java.text.DecimalFormat;import java.util.Scanner;public class Acm2001 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {double x1 = sc.nextDouble();double y1 = sc.nextDouble();double x2 = sc.nextDouble();double y2 = sc.nextDouble();double result = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));DecimalFormat df = new DecimalFormat("#.##");// 这种形式如果结果是整数的话,那么他不会有小数点,只有在是小数的情况下才能保留小数System.out.println(df.format(result));// BigDecimal bd = new BigDecimal(result);// System.out.println(bd.setScale(2, BigDecimal.ROUND_HALF_UP));}}}

0 0