萍聚社区-德国热线-德国实用信息网

 找回密码
 注册

微信登录

微信扫一扫,快速登录

萍聚头条

查看: 581|回复: 0

1-1-10-6 Java 中如何象在C里面的SCANF那样输入 int 型整数

[复制链接]
发表于 2003-2-6 22:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册 微信登录

x

  1. 发信人: bloodflower (雪人), 信区: Java      
  2. 标  题: Re: Java 中如何象在C里面的SCANF那样输入 int 型整数
  3. 发信站: BBS 水木清华站 (Thu Oct 26 15:44:41 2000)


  4. 【 在 chen28 (水獭) 的大作中提到: 】
  5. :       如题  !


  6. //Scanf.java

  7. import java.io.*;
  8. public class Scanf{
  9.     public static void main(String[] args)
  10.     {
  11.         DataInputStream din=new DataInputStream(System.in);
  12.         String str;
  13.         int a=0;
  14.         System.out.print("Input the integer number:");
  15.         System.out.flush();

  16.         try{
  17.             str=din.readLine();
  18.             a=Integer.parseInt(str);
  19.         }
  20.         catch (NumberFormatException e)
  21.             {}
  22.         catch (IOException e )
  23.             {}
  24.         System.out.println("The number you input is:"+Integer.toString(a));

  25.     }

复制代码
Die von den Nutzern eingestellten Information und Meinungen sind nicht eigene Informationen und Meinungen der DOLC GmbH.
您需要登录后才可以回帖 登录 | 注册 微信登录

本版积分规则

手机版|Archiver|AGB|Impressum|Datenschutzerklärung|萍聚社区-德国热线-德国实用信息网 |网站地图

GMT+2, 2024-5-21 21:10 , Processed in 0.053410 second(s), 19 queries , MemCached On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表