Bestcoder Pro.ID 2001 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
2016-04-22 14:56
531 查看
import java.util.Scanner; //import java.lang.Math.*; //import java.text.*; /** * * @solution : 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。 * @input : 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。 * @output :对于每组输入数据,输出一行,结果保留两位小数。 * * @discription com.acmcoder.acm.ProblemID2001.Main.java * @author wuyanhui * @date Apr 22, 2016 -- 2:04:46 PM */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); double x1,y1,x2,y2,distance; while (in.hasNext()) { x1 = in.nextDouble(); y1 = in.nextDouble(); x2 = in.nextDouble(); y2 = in.nextDouble(); distance = Math.hypot(x1 - x2,y1 - y2); //System.out.println(distance); System.out.println(String.format("%.2f", distance)); } in.close(); } }
//注意:保留两位小数、实数和整数的区别(double和int)
相关文章推荐
- CentOS 7 firewalld使用简介
- dict & set
- JS倒计时代码汇总
- 将eclipse中的project配置到Tomcat
- 作业调度模拟程序
- ES6新特性概览
- 转载/JSTL/attribute value does not accept any express
- linux之vim命令使用
- Scanner类用法
- LeetCode 73. Set Matrix Zeroes
- Node 究竟是什么
- win10+boost for gcc
- 将制作好的系统安装到硬盘上
- xmarin.android for vs2015使用百度地图api3.6.1
- iOS----自定义UIView,绘制一个UIView
- 1001. 害死人不偿命的(3n+1)猜想 (15)
- 最牛x的滚动插件 – jquery的iscroll插件(附上下拉刷新消息demo)
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory的解决方法
- iOS UserAgent 设置
- CSS3过渡