IT Life
console输入字符串方法
1
class
console
2
{
3
public
static
String readLine()
4
{
int
ch;
5
String r
=
""
;
6
boolean
done
=
false
;
7
while
(
!
done)
8
{
try
9
{ ch
=
System.in.read();
10
if
(ch
<
0
||
(
char
)ch
==
'
\n
'
)
11
done
=
true
;
12
else
if
((
char
)ch
!=
'
\r
'
)
//
weird--it used to do \r\n translation
13
r
=
r
+
(
char
) ch;
14
}
15
catch
(java.io.IOException e)
16
{ done
=
true
;
17
}
18
}
19
return
r;
20
}
21
}
22
public
class
ReadLine
23
{
24
public
static
void
main(String[] args)
25
{
26
System.out.println(
"
Please input a string :
"
);
27
String s
=
console.readLine();
28
System.out.println(
"
What you have input is:\n
"
+
s);
29
}
30
31
}
posted on 2006-07-28 22:14
tony-dl
阅读(183)
评论(0)
编辑
收藏
所属分类:
J2se->java.lang
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
My Links
BlogJava
首页
联系
聚合
管理
Blog Stats
Posts - 0
Stories - 12
Comments - 0
Trackbacks - 0
留言簿
给我留言
查看公开留言
查看私人留言
随笔分类
NetWorking
(RSS)
文章分类
Career(2)
(RSS)
En->Spoken(1)
(RSS)
Interview(1)
(RSS)
IT Industry
(RSS)
J2se->encoding(1)
(RSS)
J2se->jar(2)
(RSS)
J2se->java.io(1)
(RSS)
J2se->java.lang(1)
(RSS)
J2se->java.util
(RSS)
JUnit(1)
(RSS)
Networking Foundation(1)
(RSS)
Project Management(1)
(RSS)
文章档案
2006年10月 (8)
2006年7月 (4)
新闻分类
IT业界(2)
(RSS)
新闻档案
2006年10月 (2)
最新随笔
搜索
积分与排名
积分 - 3058
排名 - 3568
最新评论