您的位置:首页 > 编程语言

编程:从键盘输入一个字符串 最终以读的方式在显示屏输出

2013-02-01 13:23 363 查看
/*
System.in  代表的是键盘
System.ont 代表默认的显示器

编程:从键盘输入一个字符串 最终以读的方式在显示屏输出

步骤:
1:分配一快字符串内存
2:定义一个缓冲区流  将键盘输入的字符串放到缓冲区内
3:调用缓冲流中的方法 readLine() 读取一个文本行。
*/
import java.io.*;
class TestRead
{
public static void main(String[] args)
{
String str =null;
//如何从键盘上付个值,把这个值给str,通过BufferedReader缓冲流 来实现
try
{
BufferedReader be = new BufferedReader(new InputStreamReader(System.in));
str = be.readLine();
System.out.print("str="+str);
}
catch (Exception e)
{
}

}
}
总结:

static InputStream
in


“标准”输入流。
in 输入流 返回的是InputStream 包裹流 所以要 new InputStreamReader(System.in));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐