
import java.util.Scanner;public class ScannerDemo {public static void main(String[] args) {Scanner scan = new Scanner(System.in);// 从键盘接收数据// next方式接收字符串System.out.println("next方式接收:");// 判断是否还有输入if (scan.hasNext()) {String str1 = scan.next();System.out.println("输入的数据为:" + str1);}scan.close();}}
next()方法后面加Int,nextInt()获取Int类型,以此类推
next()获取字符串