Android(java)学习笔记97:Scanner类使用
2015-06-02 21:12
141 查看
package cn.itcast_01; /* * Scanner:用于接收键盘录入数据。 * * 前面的时候: * A:导包 * B:创建对象 * C:调用方法 * * System类下有一个静态的字段: * public static final InputStream in; 标准的输入流,对应着键盘录入。 * * InputStream is = System.in; * * class Demo { * public static final int x = 10; * public static final Student s = new Student(); * } * int y = Demo.x; * Student s = Demo.s; * * * 构造方法: * Scanner(InputStream source) */ import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { // 创建对象 Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.println("x:" + x); } }
package cn.itcast_02; import java.util.Scanner; /* * 基本格式: * public boolean hasNextXxx():判断是否是某种类型的元素 * public Xxx nextXxx():获取该元素 * * 举例:用int类型的方法举例 * public boolean hasNextInt() * public int nextInt() * * 注意: * InputMismatchException:输入的和你想要的不匹配 */ public class ScannerDemo { public static void main(String[] args) { // 创建对象 Scanner sc = new Scanner(System.in); // 获取数据 if (sc.hasNextInt()) { int x = sc.nextInt(); System.out.println("x:" + x); } else { System.out.println("你输入的数据有误"); } } }
相关文章推荐
- Android与MVC设计模式
- android apk 反破解手段
- Android的ProgressBar进度条-android学习之旅(三十一)
- android 带清除功能的EditText
- Android的ProgressBar进度条-android学习之旅(三十一)
- Android的ProgressBar进度条-android学习之旅(三十一)
- Android中,控件下按效果的两种实现方式!
- 关于goole IO大会发布的android M和android studio1.3的更新
- Android底层驱动开发(一)
- Android之NDK开发
- android 上传文件
- android开发资源收集贴
- Android 自动化测试之------ Monkey工具
- Android Studio使用jni、so库
- Android 数据库框架ormlite 使用精要
- android Launcher基础知识
- Android Audio 音频输出设备切换
- Android 官方博客 - Android应用程序的内存分析(翻译)(转)
- Android编程宝典-第一章-初识Android-笔记
- 菜鸟学Android笔记(十六):零散的知识点