Java IO流--标准输入System.in,输出流System.out的使用

博主前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住也分享一下给大家,
👉点击跳转到网站

前言:

  1. System.in : 标准的输入流,默认从键盘输入
  2. System.out : 标准的输出流,输出到控制台中
  3. 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();
            }
        }

    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路宇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值