博主前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住也分享一下给大家,
👉点击跳转到网站
前言:
- System.in : 标准的输入流,默认从键盘输入
- System.out : 标准的输出流,输出到控制台中
- System类的setIn(InputStream is)和setOut(OutputStream os)方式重新指定输入和输出的流
System.in和System.out的具体使用详解:
public class InputAndOut {
public static void main(String[] args) {
//System类的 public final static InputStream in = null;
//System.in 编译类型 InputStream
//System.in 运行类型 BufferedInputStream
//表示的是标准输入:键盘
System.out.println(System.in.getClass());
//1. public final static PrintStream out = null;
//2.编译类型 PrintStream
//3.运行类型 PrintStream
//4.表示标准输出 显示器
System.out.println(System.out.getClass());
System.out.println("hello");
Scanner scanner = new Scanner(System.in);
System.out.println("输入内容");
String next = scanner.next();
System.out.println("next=" + next);
}
}
练习:
从键盘输入字符串,要求将读取到的整行字符串转成大写输出,然后继续进行输入操作,直至当输入“e”或“exit”时,退出程序
public class OtherStreamTest {
public static void main(String[] args) {
BufferedReader bis =null;
try {
InputStreamReader isr = new InputStreamReader(System.in);
bis = new BufferedReader(isr);
while (true) {
System.out.println("请输入字符串:");
String data;
data = bis.readLine();
if (data.equals("e") || data.equals("exit")) {
System.out.println("程序结束");
break;
}
String s = data.toUpperCase();
System.out.println(s);
}
}catch (Exception e){
e.printStackTrace();
}finally {
try {
if (bis!=null) {
bis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}