初学者的一个问题,实在是没地方找,望高手相助

ilsuq 2004-09-04 05:17:08
在JAVA里用什么语句可以实现C中scanf的功能啊,我想用一个int变量接收从键盘中输入的数字啊,高手解答一下,谢谢了。
...全文
87 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
import java.io.*;
class ReadLine{
public static void main(String[] args) throws IOException{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
do{
str=br.readLine();
System.out.println(str);

}while(!str.equals("stop"));

}
}
wdhs 2004-09-04
  • 打赏
  • 举报
回复
public static void main(String[] args) throws Exception{
byte[] inputString = new byte[255];
System.in.read(inputString, 0, 255);
System.out.println(new String(inputString));
}
ilsuq 2004-09-04
  • 打赏
  • 举报
回复
可是我输入一下代码,显示得到的数和我输入的不一样啊,为什么呀?
import java.io.*;
public class temp {

public static void main(String[] args)
throws IOException
{
int i=System.in.read();
System.out.print(i);
}
}
wdhs 2004-09-04
  • 打赏
  • 举报
回复
System.in.read()

62,623

社区成员

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

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