请问怎么接收键盘输入啊?

dianhui 2005-07-19 03:38:54
我是一个刚刚学习JAVA的小虾.对于JAVA中的接收键盘输入我到现在还不知道!
去想一定是有很多方法的!希望大哥大姐帮我解解难!
我自己写了一个,可是不对,收到的数据根本就不是我输入的!
代码如下:
try
{
this.year=(int)System.in.read() ;
this.month=(int)System.in.read();
this.datatime=(int)System.in.read();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
...全文
149 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sophie1129 2005-07-23
  • 打赏
  • 举报
回复
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
String str = new String();
try{
str = br.readLine();
}catch(IOException e){
}
system.out.println(str);
edward0716 2005-07-20
  • 打赏
  • 举报
回复
回复人: believefym(feng)
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
String str = new String();
try{
str = br.readLine();
}catch(IOException e){
}
believefym 2005-07-19
  • 打赏
  • 举报
回复
楼主得不到想要的数,看看下面的api文档吧,read读的是byte

read
public abstract int read()
throws IOExceptionReads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.


Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.
believefym 2005-07-19
  • 打赏
  • 举报
回复
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
String str = new String();
try{
str = br.readLine();
}catch(IOException e){
}

//str就是你输入的一行了,如果要得到整数 ,可以再转一下int i = Integer.parseInt(str);
//其他类似
dianhui 2005-07-19
  • 打赏
  • 举报
回复
怎么没人帮我呢?

58,453

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧