获取键盘录入信息

来源:互联网 发布:个人姓名的com域名价格 编辑:程序博客网 时间:2024/04/30 15:41
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());}elsesb.append((char)ch);}}}

0 0
原创粉丝点击