| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2558 人关注过本帖
标题:为什么输入密码错误后还可以继续操作 在哪里加返回值
只看楼主 加入收藏
qq995354156
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2016-11-18
结帖率:100%
收藏
 问题点数:0 回复次数:4 
为什么输入密码错误后还可以继续操作 在哪里加返回值
;
import java.util.*;

public class as {
    static int zhanghao = 123456789;
    static int mima = 123456;
    static int yue = 5000;
    static Scanner in = null;
    public as(int people, int mima) {
        this.mima = mima;
    }
    public static void main(String[] args) {
        chongxindenglu();
        int count = 1;
        while (count != 0) {
            System.out.println("1、查询余额");
            System.out.println("2、取款");
            System.out.println("3、存款");
            System.out.println("4、修改密码");
            System.out.println("5、结束交易");
            System.out.println("====================");
            System.out.println("请选择交易(1-5)");
            count = in.nextInt();
            switch (count) {
            case 1:
                System.out.println(10000);
                System.out.println();
                break;
            case 2:
                quKuan();
                break;
            case 3:
                cunKuan();
                break;
            case 4:
                xiugai();
                break;
            case 5:
                System.exit(0);
            }
        }
    }

    public static void quKuan() {
        System.out.println("请输入取款金额:");
        int qukuanjine = in.nextInt();
        if (qukuanjine > 5000) {
            System.out.println("取款金额不能大于5000" + "\n");
        } else {
            if (qukuanjine % 100 != 0) {
                System.out.println("取款金额必须为100的整数倍" + "\n");
            } else {
                yue = yue - qukuanjine;
                System.out.println("您取出了" + qukuanjine + "元,您现在的余额为:" + yue
                        + "元" + "\n");
            }
        }
    }

    public static void cunKuan() {
        System.out.println("请输入存款金额");
        int cunkuanjine = in.nextInt();
        if (cunkuanjine < 0) {
            System.out.println("存款金额不能小于0");
        } else {
            yue = yue + cunkuanjine;
            System.out.println("您已成功存入:" + cunkuanjine + "元,您现在总余额为:" + yue
                    + "元" + "\n");
        }
    }

    public static void xiugai() {
        System.out.println("请输入您的密码:");
        int mima1 = in.nextInt();
        if (mima1 == mima) {
            System.out.println("请输入新密码:");
            mima = in.nextInt();
            System.out.println("您的密码已修改为:" + mima + "\n");
        } else {
            System.out.println("密码输入错误:" + "\n");
        }
    }

    public static void chongxindenglu() {
        System.out.println("欢迎使用***银行ATM");
        System.out.println("====================");
        in = new Scanner(System.in);
        System.out.println("请输入登录密码:");
        int denglumima = in.nextInt();
        if ( denglumima == mima){
            System.out.println("帐号登录成功" + "\n");
            }
        else{
            System.out.println("密码输入错误,登录失败" + "\n");
        }
    }
}

[此贴子已经被作者于2017-4-24 19:31编辑过]

搜索更多相关主题的帖子: 输入密码 public people import count 
2017-04-24 19:17
qq995354156
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2016-11-18
收藏
得分:0 
import java.util.*;

public class as {
    static int zhanghao = 123456789;
    static int mima = 123456;
    static int yue=1000+(int)(Math.random()*4000);
    static Scanner in = null;
    public as(int mima) {
        this.mima = mima;   
    }
    public static void denglu() {
        System.out.println("欢迎使用***银行ATM");
        System.out.println("====================");
        in = new Scanner(System.in);
        int i=0;
        do{
        System.out.println("请输入登录密码:");
        int denglumima = in.nextInt();
        if ( denglumima == mima){
            System.out.println("帐号登录成功" + "\n");
        break;}
        else{
            System.out.println("密码输入错误,登录失败" + "\n");
        i++;
        if(i==3){
            System.out.println("密码输入错误3次,银行卡被冻结");
            System.exit(0);
;        }
        }
        }
        while(i<3);
    }
    public static void main(String[] args) {
        denglu();
        
        int count = 1;
        while (count != 0) {
            System.out.println("1、查询余额");
            System.out.println("2、取款");
            System.out.println("3、存款");
            System.out.println("4、修改密码");
            System.out.println("5、结束交易");
            System.out.println("====================");
            System.out.println("请选择交易(1-5)");
            count = in.nextInt();
            switch (count) {
            case 1:
                System.out.println(1000+(int)(Math.random()*4000));
                System.out.println();
                break;
            case 2:
                quKuan();
                break;
            case 3:
                cunKuan();
                break;
            case 4:
                xiugai();
                break;
            case 5:
                System.exit(0);
            }
        }
    }


    public static void quKuan() {
        System.out.println("请输入取款金额:");
        int qukuanjine = in.nextInt();
        if (qukuanjine > 5000) {
            System.out.println("取款金额不能大于5000" + "\n");
        } else {
            if (qukuanjine % 100 != 0) {
                System.out.println("取款金额必须为100的整数倍" + "\n");
            } else {
                yue = yue - qukuanjine;
                System.out.println("您取出了" + qukuanjine + "元,您现在的余额为:" + yue
                        + "元" + "\n");
            }
        }
    }

    public static void cunKuan() {
        System.out.println("请输入存款金额");
        int cunkuanjine = in.nextInt();
        if (cunkuanjine < 0) {
            System.out.println("存款金额不能小于0");
        } else {
            yue = yue + cunkuanjine;
            System.out.println("您已成功存入:" + cunkuanjine + "元,您现在总余额为:" + yue
                    + "元" + "\n");
        }
    }

    public static void xiugai() {
        System.out.println("请输入您的密码:");
        int mima1 = in.nextInt();
        if (mima1 == mima) {
            System.out.println("请输入新密码:");
            mima = in.nextInt();
            System.out.println("您的密码已修改为:" + mima + "\n");
        } else {
            System.out.println("密码输入错误:" + "\n");
        }
    }
}
2017-04-24 20:19
zsh981022984
Rank: 3Rank: 3
来 自:湖南
等 级:论坛游侠
威 望:6
帖 子:36
专家分:153
注 册:2015-12-6
收藏
得分:0 
下面这是修改后的吗,感觉密码测试没有问题啊
图片附件: 游客没有浏览图片的权限,请 登录注册

因为有了因为,所以有了所以,既然已成既然,何必再说何必
2017-04-24 22:33
qq995354156
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2016-11-18
收藏
得分:0 
回复 3楼 zsh981022984
是啊
2017-05-04 20:48
纵横阳仔
Rank: 7Rank: 7Rank: 7
来 自:自学成才的火星人儿
等 级:贵宾
威 望:26
帖 子:147
专家分:698
注 册:2016-10-20
收藏
得分:0 
你出错的原因是因为没有使用循环来进行控制
你可以在登陆的地方设置死循环,只有登陆成功才可以跳出
 public static void chongxindenglu() {
        System.out.println("欢迎使用***银行ATM");
        System.out.println("====================");
        in = new Scanner(System.in);
       while(true){
        System.out.println("请输入登录密码:");
        int denglumima = in.nextInt();
        if ( denglumima == mima){
            System.out.println("帐号登录成功" + "\n");
             break;
            }
        else{
            System.out.println("密码输入错误,登录失败" + "\n");
        }
        }
    }

[此贴子已经被作者于2017-5-8 21:44编辑过]

2017-05-08 21:43
快速回复:为什么输入密码错误后还可以继续操作 在哪里加返回值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029608 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved