zoukankan      html  css  js  c++  java
  • 7、Reverse Root

    The problem is so easy, that the authors were lazy to write a statement for it!
     
    Input
    The input stream contains a set of integer numbers Ai (0 ≤ Ai ≤ 1018). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.

    Output

    For each number Ai from the last one till the first one you should output its square root. Each square root should be printed in a separate line with at least four digits after decimal point.
    解题思路:   这道题有两个点。其一为 由于输入的数据不能确定数目,而且还不  是文件输入,所以产生了捕捉数据流尾的问题, 调试的时候如果是在windows下,可以通过输入“Ctrl+z”结束输入;其二为Java如何保留四位小数,这里使用
    1 public static String formatDouble(double d) {
    2      DecimalFormat df = new DecimalFormat("#.0000");
    3      return df.format(d);
    4 }
    解决。java提供 DecimalFormat类,用最快的速度将数字格式化为需要的样子
    具体程序:
     1 import java.text.*;
     2 import java.util.*;
     3 public class ReverseRoot {
     4      public static void main(String[] args) {
     5           double[] Num=new double[30000];
     6           double temp;
     7           int n=0;
     8           Scanner scanner=new Scanner(System.in);
     9           temp=scanner.nextDouble();
    10           Num[n++]=Math.sqrt(temp);
    11           while(scanner.hasNext()){
    12               temp=scanner.nextDouble();
    13               Num[n++]=Math.sqrt(temp);
    14           }
    15           for(int i=n-1;i>=0;i--){
    16               System.out.println(formatDouble(Num[i]));
    17           }
    18      }
    19      public static String formatDouble(double d) {
    20         DecimalFormat df = new DecimalFormat("#.0000");
    21         return df.format(d);
    22     }
    23 }

    由本题得到的感悟:感觉自己好长时间没碰java,有点生疏,以后要加强训练。

  • 相关阅读:
    phonegap 拍照从相机中获取
    .net 保存datatable保存成csv文件
    常见空间算法【转】
    去除HTML标记 修改p标签为br,修改br为br,保留img标签
    C# access to the path is denied
    phonegap 通过URI获取文件大小
    PowerDesigner 注释 名称【转】
    sql server保存图片
    C#打开自定义文件
    【转】C# AderTemplates 2.0 轻量级模板引擎
  • 原文地址:https://www.cnblogs.com/langzi1996/p/6408053.html
Copyright © 2011-2022 走看看