社区
Java SE
帖子详情
一个简单的输入问题
zhangmingpowerman
2007-07-03 08:36:17
请问各位大侠如何在Java中使用类似scanf的输入函数?我找了n久都米找到
...全文
295
9
打赏
收藏
一个简单的输入问题
请问各位大侠如何在Java中使用类似scanf的输入函数?我找了n久都米找到
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
joejoe1991
2007-07-17
打赏
举报
回复
Scanner BufferedReader
CrazyGou
2007-07-17
打赏
举报
回复
脑残...
zhangmingpowerman
2007-07-17
打赏
举报
回复
多谢各位前辈的指点 小弟经过研究自己做了一个类 用下来感觉还不错 现在贴上来给大家一起分享一下!还希望各位多多指点啊!
import java.io.*;
class ConsoleInPut
{
private BufferedReader in;//定义输入输出流对象
private String str;//定义String变量以便接受输入字符串
private char []ch=new char[1];//定义char[]变量以便接受输入字符串
private int num;//定义int变量用途同上
private float fl;//定义float变量
private double dou;//定义double变量
/*构造函数 实例化输入流对象 实例化类的属性*/
public ConsoleInPut()
{
this.in = new BufferedReader(new InputStreamReader(System.in));//实例化输入流对象
this.str="";//以下为初始化各类型的变量 以便处理I/O异常
this.ch[0]='0';
this.num=0;
this.fl=0f;
this.dou=0d;
}
/*输入字符串数据方法*/
public String strInPut() throws NumberFormatException
{
boolean b=true;
do
{
try
{
this.str= in.readLine();
b=false;
}
catch(IOException e)
{
System.out.println("程序发生输入输出流的异常!请重试!");
b=true;
}
catch(NumberFormatException e1)
{
System.out.println("输入的数据类型不匹配!请重试!");
b=true;
}
}
while (b);
return this.str;
}
/*输入单个字符数据方法*/
public char charInPut() throws NumberFormatException
{
boolean b=true;
do
{
try
{
this.str=in.readLine();
this.ch=this.str.toCharArray();
b=false;
}
catch (IOException e)
{
System.out.println("程序发生输入输出流的异常!请重试!");
b=true;
}
catch(NumberFormatException e1)
{
System.out.println("输入的数据类型不匹配!请重试!");
b=true;
}
}
while (b);
return this.ch[0];
}
/*输入int类型数据方法*/
public int intInPut() throws NumberFormatException
{
boolean b=true;
do
{
try
{
this.str=in.readLine();
this.num=Integer.parseInt(this.str);//封装类Integer的方法parseInt将String转换成int
b=false;
}
catch(IOException e)
{
System.out.println("程序发生输入输出流的异常!请重试!");
b=true;
}
catch(NumberFormatException e1)
{
System.out.println("输入的数据类型不匹配!请重试!");
b=true;
}
}
while (b);
return this.num;
}
/*输入float类型数据方法*/
public float floatInPut() throws NumberFormatException
{
boolean b=true;
do
{
try
{
this.str=in.readLine();
this.fl=Float.parseFloat(this.str);//封装类Float的方法parseFloat将String转换成float
b=false;
}
catch(IOException e)
{
System.out.println("程序发生输入输出流的异常!请重试!");
b=true;
}
catch(NumberFormatException e1)
{
System.out.println("输入的数据类型不匹配!请重试!");
b=true;
}
}
while (b);
return this.fl;
}
/*输入double类型数据方法*/
public double doubleInPut() throws NumberFormatException
{
boolean b=true;
do
{
try
{
this.str=in.readLine();
this.dou=Double.parseDouble(this.str);//封装类Double的方法parseDouble将String转换成double
b=false;
}
catch(IOException e)
{
System.out.println("程序发生输入输出流的异常!请重试!");
b=true;
}
catch(NumberFormatException e1)
{
System.out.println("输入的数据类型不匹配!请重试!");
b=true;
}
}
while (b);
return this.dou;
}
}
yondy
2007-07-03
打赏
举报
回复
jdk1.5以后有个Scanner
stefli
2007-07-03
打赏
举报
回复
System.in
自己就搜索这个
bsfxli
2007-07-03
打赏
举报
回复
up
tdy1234
2007-07-03
打赏
举报
回复
不时有个函数System.in吗 你去看下API啊
zhangmingpowerman
2007-07-03
打赏
举报
回复
多谢各位大侠的指点 小弟已经豁然开朗啦
weiqiwei
2007-07-03
打赏
举报
回复
http://java.d9t3.com/ViewDownInfo.asp?ID=10
简单
的注册登录功能(JavaWeb项目)
在JavaWeb开发中,构建
一个
简单
的注册登录功能是基础且重要的任务。这涉及到用户认证、数据持久化以及前端交互等多个方面。在这个项目中,我们主要关注的是如何利用MySQL数据库存储用户信息,以及如何通过MVC(Model...
Android 智能问答机器人的实现
4. **问答模型**:可以是
一个
简单
的关键词匹配规则,或者是
一个
训练好的机器学习模型,用于理解和回答
问题
。 5. **数据存储与检索**:可能包含
一个
本地数据库或API接口,用于存储和检索
问题
与答案的配对。 6. **结果...
自动填充功能实现-- 实例源码
1. **数据存储**:自动填充功能需要
一个
数据源来提供匹配选项,这可能是
一个
简单
的数组或者与服务器进行异步交互的API。 2. **事件监听**:通过监听用户在
输入
框中的键入事件,如`input`或`keydown`,来触发自动...
Android省市区三级联动滚轮选择——Cascade_Master
"Android省市区三级联动滚轮选择——Cascade_Master"是
一个
专门为解决这一
问题
而设计的组件。这个组件是从实际项目中提炼出来的,旨在提供
一个
高效、直观且易于集成的解决方案。 该组件是基于开源库`Android-wheel`...
commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar程序文件
这个库提供了
一个
简单
且可扩展的API,使得开发人员可以轻松地解析和处理上传到服务器的文件。它包括以下主要功能: 1. **多部分解析**:FileUpload可以解析HTTP请求中的多部分数据,将其分解为单独的字段和文件。 2...
Java SE
62,634
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章