
Java一个取款的问题求解决
3个回答
展开全部
直接附上代码了
import java.util.Scanner;
public class Withdraw {
public static void main(String[] args) {
int n=3; //控制登录次数
String password = "111111"; //登录密码
Scanner sc = new Scanner(System.in);
boolean flag = true; //取款成功后将该标识符设置为false可退出交易
while(n-->0&&flag){
String string = sc.nextLine();
if(string.equals(password)){ //判断输入密码是否正确
System.out.println("请输入你需要取款的金额");
while(true){
int amount = sc.nextInt(); //获取输入的取款金额
if(amount>=0&&amount<=1000&&amount%100==0){ //金额应该为0-1000之间,且为100的整数
System.out.println("取款金额为:"+amount);
System.out.println("交易完成,请取卡");
flag=false; //取款成功,则设置标识符,退出交易
break;
}
else{ //不满足条件则重新输入金额
System.out.println("请重新输入金额:");
}
}
}
else {
if(n!=0) continue;
else{
System.out.println("密码错误,请取卡");
break;
}
}
}
}
}
import java.util.Scanner;
public class Withdraw {
public static void main(String[] args) {
int n=3; //控制登录次数
String password = "111111"; //登录密码
Scanner sc = new Scanner(System.in);
boolean flag = true; //取款成功后将该标识符设置为false可退出交易
while(n-->0&&flag){
String string = sc.nextLine();
if(string.equals(password)){ //判断输入密码是否正确
System.out.println("请输入你需要取款的金额");
while(true){
int amount = sc.nextInt(); //获取输入的取款金额
if(amount>=0&&amount<=1000&&amount%100==0){ //金额应该为0-1000之间,且为100的整数
System.out.println("取款金额为:"+amount);
System.out.println("交易完成,请取卡");
flag=false; //取款成功,则设置标识符,退出交易
break;
}
else{ //不满足条件则重新输入金额
System.out.println("请重新输入金额:");
}
}
}
else {
if(n!=0) continue;
else{
System.out.println("密码错误,请取卡");
break;
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询