java得到键盘录入,并返回大写,输入over则终止输入
public static void main(String[] args) throws IOException {readKey_2();}/** 得到键盘录入,并返回大写,输出over则停止*/public static void readKey_2() throws IOException {//接收容器StringBuilder sb =
·
public static void main(String[] args) throws IOException {
readKey_2();
}
/*
* 得到键盘录入,并返回大写,输出over则停止
*/
public static void readKey_2() throws IOException {
//接收容器
StringBuilder sb = new StringBuilder();
InputStream in = System.in;
int ch = 0;
while((ch=in.read())!=-1){
if(ch=='\r')
continue;
if(ch=='\n'){
String temp = sb.toString();
if(temp.equals("over"))
break;
System.out.println(temp.toUpperCase());
sb.delete(0, sb.length());
}else
sb.append((char)ch);
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)