package com.liu.scanner; import java.util.Scanner; public class Demo1 { public static void main(String[] args){ //从键盘接收数据 Scanner scanner = new Scanner(System.in); System.out.println("请输入"); //判断是否有输入 if (scanner.hasNextLine()){ String str = scanner.nextLine(); System.out.println("输入为:"+str); } scanner.close(); } }