展开全部
private int balance = 0;
private String username = "A";
private String password = "B";
public void bank() {
Scanner scan = new Scanner(System.in);
String temp;
while (true) {
System.out.println("输入账号:62616964757a686964616fe78988e69d8331333361316662");
if (scan.hasNext()) {
temp = scan.next();
if (temp.equals(username)) {
break;
} else {
System.out.println("输入错误");
}
}
}
while (true) {
System.out.println("输入密码:");
if (scan.hasNext()) {
temp = scan.next();
if (temp.equals(password)) {
break;
} else {
System.out.println("输入错误");
}
}
}
System.out.println("登录成功");
while (true) {
System.out.println("输入操作:");
if (scan.hasNext()) {
temp = scan.next();
switch (temp) {
case "存款":
int x = 0;
while (true) {
System.out.println("输入存款金额:");
if (scan.hasNextInt()) {
x = scan.nextInt();
break;
} else {
System.out.println("输入错误");
scan.next();
}
}
balance += x;
break;
case "取款":
int y = 0;
while (true) {
System.out.println("输入取款金额:");
if (scan.hasNextInt()) {
y = scan.nextInt();
if (balance
System.out.println("余额不足");
continue;
}
break;
} else {
System.out.println("输入错误");
scan.next();
}
}
balance -= y;
break;
case "余额":
System.out.println("余额:" + balance);
break;
case "终止":
System.exit(0);
default:
System.out.println("未知操作");
}
}
}