import java.util.Scanner;
public static void main(String[] str){
Scanner scan = new Scanner(System.in);
if(scan.hasNext()){
System.out.println(scan.next())
}
}
1. hasNext() 与hasNextLine()方法都会阻塞,直到下一个字符串段 或 下一行进来时才会解除阻塞,返回ture,即永远不会返回false;
2. hasNext()是以空格或换行为标志来判断下一个的,hasNextLine()是以换行为标志来判断下一个的;
3. hasNextInt()也是以空格或换行为标志来判断下一个的,也会阻塞的。但是!! 如果字符串段不是数字,那么就会直接抛出异常,停止程序!!!! 所以需要慎用!!!
next() 与 nextLine() 也是阻塞的!!!!!