• scanner


    Scanner 类

         hasNextInt()  :   判断输入的是否是int ,若是int  返回true   

        hasNextXxx() :  每个基本数据类型都有  一个类似的这样的方法

        

      两个常用的方法:
        * public int nextInt():获取一个int类型的值
        * public String nextLine():获取一个String类型的值

      

      nextLine()  可以接收任意类型的数据,遇到、 就结束

    public class test1 {
        /*
         * 模拟登陆: 给三次机会  并提示还有几次
         * */
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int tries;
            String username = "admin";
            String password = "admin";
            for (int i = 0; i < 3; i++) {
                System.out.println("请输入用户名");
                String un = s.nextLine();
                System.out.println("请输入密码");
                String pw = s.nextLine();
                tries = 2 - i;
                if(username.equals(un)&&password.equals(pw)){
                    System.out.println("欢迎"+un+"登陆");
                    break;  // 跳出循环
                }else {
                    if (i==2) {
                        System.out.println("您的错误次数已到,请明天再来");
                    } else {
                        System.out.println("用户名或密码错误,您还有"+tries+"次机会");
                    }
                    
                }
                
            }
        }
    
    }
    竹杖芒鞋轻胜马,一蓑烟雨任平生。 回首向来萧瑟处,也无风雨也无晴。
  • 相关阅读:
    win10重装vscode后打不开
    GDB 调试
    分布式架构--概述一
    汇编语言答案(王爽)第三版
    matplotlib之热成像图
    matplotlib之等高线图
    matplotlib之饼状图
    matplotlib之条形图绘制
    360图片网站批量抓取
    数据转换
  • 原文地址:https://www.cnblogs.com/yaobiluo/p/11302031.html
Copyright © 2020-2023  润新知