java 简单的输入BufferedReader和Scanner

//简单的整数
import java.io.*;
import java.util.*;
public class io{
	 public static void main(String[] args)throws IOException{
		 Scanner sc=new Scanner(System.in);
		 while(sc.hasNextInt()){
			 int x,y;
			 x=sc.nextInt();
			 y=sc.nextInt();
			 System.out.println(x+" "+y);
		 }
	 }
}

//简单的输入字符串
import java.io.*;
public class io{
         public static void main(String[] args)throws IOException{
          BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
           String s = in.readLine();
          System.out.print(s);
         }
} 
Scanner中next()与nextLine()的区别?在API文档中next()  
  查找并返回来自此扫描器的下一个完整标记。

nextLine()  
  此扫描器执行当前行,并返回跳过的输入信息。Example:输入行为:Nice to you!next():输出为:Niceelse nextLine()输出为:Nice to you! 



   

你可能感兴趣的:(java,String,IO,Class,文档,import)