publicstaticvoidmain(String[] args)throws Exception { /* 下面这是IO流包装,可以看不懂,直接套用就好*/ StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken();/*nextToken()方法相当于让光标指向下一个位置*/ int n = (int) in.nval;//获取整数; out.println(n); out.flush();/*刷新输出缓冲区并输出*/ }
输入字符串(sval)
1 2 3 4 5 6 7 8 9
publicstaticvoidmain(String[] args)throws Exception { /* 下面这是IO流包装,可以看不懂,直接套用就好*/ StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken();/*nextToken()方法相当于让光标指向下一个位置*/ String str = in.sval;/*注意:sval是获取不带空格的字符串,含有空格的字符串无法全部读取,只会获取空格之前的。并且只能用来获取含字母和数字、中英文句号的字符串。具体情况需要自行尝试,至少写者在测试时是这样的。因为网上有些说的是只能是字母串,不能含数字或其他,否则会返回null。*/ out.println(str); out.flush();/*刷新输出缓冲区并输出*/ }
多组输入
1
while (in.nextToken() != StreamTokenizer.TT_EOF) //StreamTokenizer.TT_EOF这个是个参数,就是相当于EOF了。
示例:
1 2 3 4 5 6 7 8 9 10 11 12
publicstaticvoidmain(String[] args)throws Exception { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
while (in.nextToken() != StreamTokenizer.TT_EOF){ int n = (int) in.nval; in.nextToken(); int m = (int) in.nval; out.println(n+" "+m); out.flush(); } }
publicstatic BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); publicstatic BufferedWriter cout = new BufferedWriter(new OutputStreamWriter(System.out));
publicstatic StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); publicstatic PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
/** * @Author DragonOne * @Date 2021/12/5 21:27 * @墨水记忆 www.tothefor.com */ publicclassMain{ publicstatic BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); publicstatic BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); publicstatic StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); publicstatic PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));
publicstaticvoidmain(String[] args)throws Exception { int n = nextInt(); long m = nextLong(); double d = nextDouble(); cout.println(n); cout.flush(); cout.println(m); cout.flush(); cout.println(d); cout.flush();