⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readdoubletest.java

📁 Java2核心技术卷一 配套源码,看了还不错
💻 JAVA
字号:
/**
 * @version 1.00 11 Mar 1997
 * @author Cay Horstmann
 */
 
import java.io.*;
import java.text.*;

public class ReadDoubleTest 
   // shows how to read a double the hard way
{  public static void main(String[] args) 
   {  System.out.println
         ("Enter a number, I'll add two to it.");
      double x; // the number we wish to read
      try
      {  InputStreamReader isr 
            = new InputStreamReader(System.in);
         BufferedReader br 
            = new BufferedReader(isr);
         String s = br.readLine(); 
         DecimalFormat df = new DecimalFormat();
         Number n = df.parse(s);
         x = n.doubleValue();
      }
      catch(IOException e)
      {  x = 0;
      }
      catch(ParseException e)
      {  x = 0;
      }
      System.out.println(x + 2); 
   }
}   




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -