import java.util.*;
import java.text.DecimalFormat;
class Main{
public static void main(String args[])
{Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{ double x1=cin.nextDouble();
double y1=cin.nextDouble();
double x2=cin.nextDouble();
double y2=cin.nextDouble();

double c=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
DecimalFormat df=new DecimalFormat("#0.00");
System.out.println(df.format(c));
}
}
}

此处注意要用到DecimalFormat来确定浮点后面的想要保留的小数;

import java.util.*;
class Main{
public static void main(String args[])
{Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{double x1=cin.nextDouble();
double y1=cin.nextDouble();
double x2=cin.nextDouble();
double y2=cin.nextDouble();
aa(x2-x1,y2-y1);
}}
public static void aa(double a,double b)
{ double c=Math.sqrt(a*a+b*b);
System.out.printf("%.2f",c);
System.out.println();
}
}

也可以直接用printf直接保留两位小数;

HDU2001java的更多相关文章

随机推荐

  1. JS頁面值傳遞

    <script type="text/javascript"> function GetValue() { var url=location.search; var R ...

  2. [swustoj 594] Maximum Tape Utilization Ratio

    Maximum Tape Utilization Ratio(0594) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 467 Ac ...

  3. C#调用C++函数入口点的问题 z

    C++使用 void extern __declspec(dllexport) 函数名()定义的输出函数, 在C#中调用时, 如前文所述, 使用 [DllImport("D:\VS2005P ...

  4. iframe 处理

    import java.io.File; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org ...

  5. [摘]selenium-ide编辑命令

    ----//编辑命令 selenium为我们录制的脚本不是100%符合我们的需求的,所以,编辑录制的脚本是必不可少的工作. 1.  编辑一行命令或注释. 在Table标签下选中某一行命令,命令由com ...

  6. We're Hiring A Software Tester

    测试人员的基本修养: 代码编写,不可或缺 乔布斯说:Design is not just what it looks like and feel like,design is how it works ...

  7. web_reg_find()查询信息为变量

    Action(){char *str1;//=(char*)malloc(20);char str2[10]; web_url("toLoginPage", "URL={ ...

  8. ubuntu设置固定ip

    设定IP $sudo gedit /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet st ...

  9. HDOJ-ACM1022(JAVA)

    这道题:是模拟出栈,判断出栈顺序的可能性. 基本上大家的做法都是直接模拟栈的出栈入栈并将顺序用0,1序列来表示,我暂时没想到什么好的思路. import java.util.*; import jav ...

  10. 组合数学及其应用——格路径与Schroder数

    格路径问题是探讨在如下所示中的一个格点图上,从(0,0)位置到达(p,q)所有可能的情况数.我们称这样的通路为一条格路径. 格点图: · · · · · · · · · · · · · · · · · ...