码迷,mamicode.com
首页 > 编程语言 > 详细

java:system根据输入的内容,然后输出

时间:2017-07-20 10:16:33      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:system   blog   string   csharp   int   har   内容   ==   ring   

把输入的内容输出来:根据system.in的内容System.out.println输出出来

//限制读取的字符长度
		InputStream ips = System.in;
		byte b[] = new byte[20];
		System.out.println("请输入:");
		int len = ips.read(b);
		System.out.println( new String(b, 0, len)  );
		
		
		//不限制读取的输入的字符长度
		InputStream ipt = System.in;
		System.out.println("请输入:");
		int temp = 0;
		StringBuffer buff = new StringBuffer();
		while( (temp = ipt.read()) !=-1 )
		{
			
			char c = (char)temp;
			//判断是否打回车键
			if(c == ‘\n‘)
			{
				break;
			}
			buff.append(c);
		}
		System.out.println("输入的字符是:" + buff );

  

 

java:system根据输入的内容,然后输出

标签:system   blog   string   csharp   int   har   内容   ==   ring   

原文地址:http://www.cnblogs.com/achengmu/p/7209182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!