public class ReadKeyDemo2 {
/**
* @param args
* 获取用户键盘录入的数据,并将数据变成大写,当用户输入over后,结束流
* @throws IOException
*/
public static void main(String[] args) throws IOException {
StringBuilder sb=new StringBuilder();
InputStream in=System.in;
int ch=-1;
while((ch=in.read())!=-1){
if(ch=='\r')
continue;
if(ch=='\n'){
String temp=sb.toString();
if("over".equals(temp))
break;
System.out.println(sb.toString().toUpperCase());
sb.delete(0, sb.length());
}
else
sb.append((char)ch);
}
}
}
获取键盘录入信息
最新推荐文章于 2022-03-20 16:06:58 发布