码迷,mamicode.com
首页 > 编程语言 > 详细

java Scanner

时间:2020-01-08 14:53:05      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:tin   int   scanner   lin   pre   else   next   回车   new   

初始化

Scanner scanner = new Scanner(System.in);

读取字符串

String oneStr = sc.next(); //字符串以空格结束,不包含字符串
String twoStr = sc.nextLine(); //字符串以回车结束

读取整数

if (sc.hasNext()) {    //一般会先判断再读取
    Int in=sc.nextInt();
}else{
    System.out.println("输入的不是整数!");
}
sc.close();    //最后要关闭

java Scanner

标签:tin   int   scanner   lin   pre   else   next   回车   new   

原文地址:https://www.cnblogs.com/liehen2046/p/12166227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!