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

  • 相关阅读:
    redhat 找不到eth0等网卡设备
    oracle12.2 windows 安装卸载重新学习
    Ubuntu官方推荐U盘镜像写入工具(转载别人的)
    linux sh 脚本获取命令结果变变量然后post
    img图片过长自动截取隐藏
    python 数字类型
    Pycharm 常用快捷键 转自 暮良文王
    #python输入输出
    勤学如春起之苗,不见其增日有所长。缀学如磨刀之石,不见其损日有所亏
    感冒了,好难受
  • 原文地址:https://www.cnblogs.com/langzi1996/p/6408053.html
Copyright © 2011-2022 走看看