学习日记四

初识Java(二)

  1. java.util.Scanner 是 Java5 的新特征,可以通过 Scanner 类来获取用户的输入
Scanner scan = new Scanner(System.in);//从接收用户数据
String str = scan.next();//next方式接收字符串
int i = scan.nextInt();//接收整数
String str = scan.nextLine();//nextLine方式接收字符串
scan.hasnextInt();//判断接收的数据类型,是否是Int
scan.close();//
/*区别:next不能得到带有空格的字符串,会将空白作为分隔符或结束符,如aa aa输出aa
nextLine以回车为结束符,返回回车之前的所有字符串,可以获得空白*/
posted @ 2021-02-24 10:20  孤星寒  阅读(45)  评论(0)    收藏  举报