栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java 快读快写模板及读写示例(竞赛向)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java 快读快写模板及读写示例(竞赛向)

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class 快读快写 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StreamTokenizer st = new StreamTokenizer(br);
	static PrintWriter OUT = new PrintWriter(new BufferedOutputStream(System.out));

	public static int nextInt() throws Exception {
		st.nextToken();
		return (int) st.nval;
	}

	public static double nextDouble() throws Exception {
		st.nextToken();
		return st.nval;
	}

	public static String nextStr() throws Exception {
		st.nextToken();
		return st.sval;
	}

	public static String nextLine() throws Exception {
		return br.readLine();
	}

	public static void main(String[] args) throws Exception {
		readInt();
		// readStr();
		// readLine();
	}

	public static void readInt() throws Exception {
		// 读取整型数
		int n_int = nextInt();
		int list_int[] = new int[n_int];
		for (int i = 0; i < n_int; i++) {
			list_int[i] = nextInt();
		}
		for (int i = 0; i < n_int; i++) {
			OUT.println(list_int[i]);
		}
		OUT.flush();
	}

	public static void readStr() throws Exception {
		// 读取字符串
		int n_str = nextInt();
		String list_str[] = new String[n_str];
		for (int i = 0; i < n_str; i++) {
			list_str[i] = nextStr();
		}
		for (int i = 0; i < n_str; i++) {
			OUT.println(list_str[i]);
		}
		OUT.flush();
	}

	public static void readLine() throws Exception {
		// 读取下一行
		int n_line = nextInt();
		br.readLine();// 只读了第一行中的数字,要把第一行空出去
		String list_line[] = new String[n_line];
		for (int i = 0; i < n_line; i++) {
			list_line[i] = nextLine();
		}
		for (int i = 0; i < n_line; i++) {
			OUT.println(list_line[i]);
		}
		OUT.flush();
	}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/774659.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号