java Scanner 输入输出总结

本文总结了Java中Scanner类的使用,包括println方法、Scanner的输入处理如nextInt()、nextLine(),以及如何检查是否还有下一个输入。通过示例解释了各方法在处理输入时光标的移动和对空白字符的处理。
摘要由CSDN通过智能技术生成

java 输入输出总结

println

System.out.println源码:

/**
     * Prints a String and then terminate the line.  This method behaves as
     * though it invokes {@link #print(String)} and then
     * {@link #println()}.
     *
     * @param x  The {@code String} to be printed.
     */
    public void println(String x) {
        if (getClass() == PrintStream.class) {
            writeln(String.valueOf(x));
        } else {
            synchronized (this) {
                print(x);
                newLine();//输出后面额外会加一个换行;
            }
        }
    }

Scanner

包名:import java.util.Scanner;
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.

next()

Finds and returns the next complete token from this scanner.//会将光标定位到该字符串之后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值