Java的输入输出

package qiye;

import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class shuru {
	public static void main(String args[]) throws IllegalStateException {
	/*方法一:使用Scanner类
	 * 这些方法在执行时都会阻塞,程序等待用户在输入流中输入enter键(\n)时继续执行。
	 * 这里的nextInt,hasNextInt()这些方法的调用,会判断当前字节流里面是否有东西,
	 * 没有就阻塞等待输入直到用户按enter键(\n)结束输入,在Scanner类中有一个变量needInput,
	 * 当需要读取数据时,needInput=true(也就是调用nextInt,hasNextInt()这些函数的时候)。
	 * 有一个readInput方法,当字节流中有东西可读时,让needInput=false(表示不需要阻塞等待输入);*/
	Scanner sc=new Scanner(System.in);
//	String s=sc.next();//输入字符串,以空格作为分隔符 如果输入I am a boy 只能读取到I
//	String s1=sc.nextLine();//输入字符串,以Enter键结束。如果输入I am a boy Enter键会读取到I am a boy
	int a,b;
	a=sc.nextInt();
	System.out.println(a);
	b=sc.nextInt();
	System.out.println(b);	
	

	//方法二:使用java.io.BufferedReader和java.io.InputStreamReader
/*		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=null;
		while(true) {
			str=br.readLine();
			if(str.equals("End")) {
			break;
		}
	      System.out.print(str);
		}
		*/
		//方法三:使用java.io.Console  方法三报错?
//		Console console = System.console();  
//        if (console == null) {  
//            throw new IllegalStateException("Console is not available!");  
//        } 
//        String str =null;
//        while(true){
//            str = console.readLine("请输入"); 
//            if("END".equals(str))break;
//            System.out.println(str);
//        }        


	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值