JAVA IO输入输出

在hdu上找到一个很好的总结。

package IO;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    private static Scanner in = new Scanner(new BufferedInputStream(System.in));

    public static void main(String[] args) {
        while (in.hasNext()) {
            System.out.println(in.nextInt() + in.nextInt());
        }
    }
}


//1. 格式
//        1.1 不要带上package name!
//        1.2 class name 一定要是Main
//
//2. 输入
//        2.1 scanner
//        输入肯定是new一个Scanner类,但是会有两种方式:
//        Scanner sc = new Scanner (System.in);
//        Scanner sc = new Scanner (new BufferedInputStream(System.in));//数据量大的情况下此种方式快
//        2.2 终止条件
//        万金油:while(sc .hasNext())
//        矫情一点:sc .hasNextInt()或sc .hasNextDouble()或sc .hasNextLine()
//        2.3 读值
//        int: int n = sc.nextInt();
//        double: double t = sc.nextDouble();
//        string space split(空格分割): String s = sc.next();
//        string enter split(换行分割): String s = sc.nextLine();
//
//        3. 输出
//        和C中的printf保持一致:
//        System.out.printf("%s %d %fn",arg1,arg2,arg3);
//        自带换行
//        System.out.println(arg1);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值