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,有点生疏,以后要加强训练。

  • 相关阅读:
    sql server常用
    Building Workspace has encountered a problem
    交换机端口安全Port-Security超级详解
    nginx网站502与504错误分析
    基于IP的nginx反向代理示例
    OpenMediaVault(OMV)安装omv-extras命令
    百度编辑器不能插入html标签解决方法
    如何解决关于ueditor编辑器过滤script/style标签的问题
    inux反选删除文件
    Linux下每天自动备份Mysql数据库发送到指定Email
  • 原文地址:https://www.cnblogs.com/langzi1996/p/6408053.html
Copyright © 2011-2022 走看看