初学JAVA,怎样获取控制台输入的一行字符串

阿干2 2006-03-29 03:21:23
初学JAVA,怎样获取控制台输入的一行字符串
...全文
1674 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
haitao8686 2006-03-29
  • 打赏
  • 举报
回复
System.in
gaoxiangyu123 2006-03-29
  • 打赏
  • 举报
回复
学一招
joneyj2ee 2006-03-29
  • 打赏
  • 举报
回复
个人觉得 Scanner很好 ^_^
weixing979 2006-03-29
  • 打赏
  • 举报
回复
Scanner不错,确实以前的方法太麻烦了.
Flowing_air 2006-03-29
  • 打赏
  • 举报
回复
Scaner好像也要的:)
qq14923349 2006-03-29
  • 打赏
  • 举报
回复
String s;
JOptionPane.showMessage****
接收再转换
Flowing_air 2006-03-29
  • 打赏
  • 举报
回复
补充一点注意 IOException,我用1.50。每次都不用exception时候总是不能编辑。:)
阿干2 2006-03-29
  • 打赏
  • 举报
回复
好,谢谢,各位.啦.....
PoemCode 2006-03-29
  • 打赏
  • 举报
回复
简单方便,甩开I/O库的烦琐。
PoemCode 2006-03-29
  • 打赏
  • 举报
回复
JDK5中引入一个新的类,很好用,可以满足你的要求。

java.util
Class Scanner

java.lang.Object
extended by java.util.Scanner

A simple text scanner which can parse primitive types and strings using regular expressions.

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

For example, this code allows a user to read a number from System.in:

Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
weixing979 2006-03-29
  • 打赏
  • 举报
回复
public class test {

public static void main(String[] args) throws IOException {

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String str = stdin.readLine();
System.out.println(str);
}
}
阿干2 2006-03-29
  • 打赏
  • 举报
回复
不用args[]
用System.in....怎么用啊..
我是用Jcreator里写的...
ysycrazy 2006-03-29
  • 打赏
  • 举报
回复
string str = args[0];

62,629

社区成员

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

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