package com.lyc;
import java.util.Scanner;

public class Demo02 {
public static void main(String[] args) {
//创建一个扫描对象,用于接收键盘数据
Scanner scanner = new Scanner(System.in);
System.out.println("使用nextLine方式接收:");
//判断用户有没有输入字符串
if (scanner.hasNext()){
//使用nextLine方式接收
String str = scanner.nextLine();
System.out.println("输出内容为"+str);
}
//凡是属于IO流的类如果不关闭会一直占用资源,养成好习惯用完就关闭
scanner.close();


}
}
posted on 2021-01-05 21:35  liuyunche  阅读(61)  评论(0编辑  收藏  举报