package priv.whs.java;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*从键盘输入字符串,要求读取到的整行字符串转换成大写输出
* 然后继续输入,知道当输入‘e’或者‘exit’是时,退出程序
*
*
* @author whs
* @date 2022-10-19
*/
public class OtherStreamTest {
public static void main(String[] args) {
BufferedReader br = null;
try {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
while (true){
System.out.println("请输入:");
String data = br.readLine();//读一整行数据
if ("e".equalsIgnoreCase(data) || "exit".equalsIgnoreCase(data)){
System.out.println("程序结束");
break;
}
System.out.println(data.toUpperCase());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
从键盘输入字符串,要求读取到的整行字符串转换成大写输出 然后继续输入,知道当输入‘e’或者‘exit’是时,退出程序
最新推荐文章于 2022-12-08 18:45:26 发布