1 package cn.itcast_01; 2  3 /* 4  * Scanner:用于接收键盘录入数据。 5  *  6  * 前面的时候: 7  *         A:导包 8  *         B:创建对象 9  *         C:调用方法10  * 11  * System类下有一个静态的字段:12  *         public static final InputStream in; 标准的输入流,对应着键盘录入。13  * 14  *         InputStream is = System.in;15  * 16  * class Demo {17  *         public static final int x = 10;18  *         public static final Student s = new Student();19  * }20  * int y = Demo.x;21  * Student s = Demo.s;22  * 23  * 24  * 构造方法:25  *         Scanner(InputStream source)26  */27 import java.util.Scanner;28 29 public class ScannerDemo {30     public static void main(String[] args) {31         // 创建对象32         Scanner sc = new Scanner(System.in);33 34         int x = sc.nextInt();35         36         System.out.println("x:" + x);37     }38 }

 1 package cn.itcast_02; 2  3 import java.util.Scanner; 4  5 /* 6  * 基本格式: 7  *         public boolean hasNextXxx():判断是否是某种类型的元素 8  *         public Xxx nextXxx():获取该元素 9  * 10  * 举例:用int类型的方法举例11  *         public boolean hasNextInt()12  *         public int nextInt()13  * 14  * 注意:15  *         InputMismatchException:输入的和你想要的不匹配16  */17 public class ScannerDemo {18     public static void main(String[] args) {19         // 创建对象20         Scanner sc = new Scanner(System.in);21 22         // 获取数据23         if (sc.hasNextInt()) {24             int x = sc.nextInt();25             System.out.println("x:" + x);26         } else {27             System.out.println("你输入的数据有误");28         }29     }30 }

更多相关文章

  1. Android判断是否挂载外置sd卡
  2. 2018-06-02 Android(安卓)Studio:创建layout-sw600dp文件夹以及
  3. Android避免进入一页面后EditText自动弹出软键盘
  4. MAC和Windows Android(安卓)Studio获取SHA1值
  5. Android基础之异步消息处理机制
  6. ANDROID 一键搞定JNI创建C头文件
  7. 使用Android(安卓)Camera2 API获取YUV数据
  8. Android(安卓)Studio配置网易mumu模拟器
  9. 私有析构函数 Android(安卓)代码分析

随机推荐

  1. Android中RelativeLayout各个属性的含义
  2. android:textAppearance是什么意思
  3. 源码解析Android中AsyncTask的工作原理
  4. pandaboard ES学习之旅——4 Android源代
  5. Android(安卓)多个Activity选项卡实现
  6. android 电容屏(二):驱动调试之基本概念篇
  7. Android中创建对话框
  8. android adb
  9. 跟着做 Android(安卓)NDK学习入门如此简
  10. Android按键添加和处理的方案