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

  • 相关阅读:
    占位
    阳光服务平台-敏捷开发
    两种方法实现带验证码的用户登录
    红警大战JAVA简单版
    JPanel与JFrame的区别
    java中import详解
    敏捷开发
    GitHub:本地项目上传与团队协作
    从结缘计算机到未来规划
    (三)微信小程序首页的分类功能和搜索功能的实现笔记
  • 原文地址:https://www.cnblogs.com/langzi1996/p/6408053.html
Copyright © 2011-2022 走看看