为什么输入密码错误后还可以继续操作 在哪里加返回值
;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编辑过]