Java第九章简答题5

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_45155377/article/details/102736570

Java第九章简答题5

import java.util.Scanner;

public class D9zjdt5 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		int mima = 0;// 密码
		int jine = 0;// 金额
		int a = 0;// 输入密码次数
		System.out.println("请输入密码");
		mima = input.nextInt();
		for (a = 3; a > 0; a--) {
			if (mima == 111111) {
				System.out.println("请输入金额");
				jine = input.nextInt();
				break;
			} else {
				System.out.println("密码错误,请重新输入");
				mima = input.nextInt();
				if (a == 1) {
					System.out.println("输入密码错误3次,退出系统,请取回您的磁卡");
				}
			}
		}
		while (jine > 0) {
			if (jine % 100 == 0 && jine <= 1000) {
				System.out.println("您取了" + jine + "元");
				System.out.print("交易完成,请取卡");
				break;
			} else {
				System.out.println("您输入的金额有误,请重新输入:");
				jine = input.nextInt();
				continue;
			}
		}
	}
}
import java.util.Scanner;

public class D9zjdt5Class {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int Password = 111111;
		int password = 0; // 密码
		int amount = 0;// 金额
		int conut = 0;// 次数
		boolean passWord = false;// 验证是否通过

		while (conut < 3 && !passWord) {
			System.out.println("请输入密码");
			password = input.nextInt();
			if (password != Password) {
				conut++;
				continue;
			}
			passWord = true;
			System.out.println("请输入金额");
			amount = input.nextInt();
			while (amount > 0) {
				if (amount % 100 == 0 && amount <= 1000) {
					System.out.println("您取了" + amount + "元");

					System.out.println("交易完成,请取卡");
					break;
				} else {
					System.out.println("您输入的金额有误,请重新输入");
					amount = input.nextInt();
					continue;
				}
			}
		}
		if (!passWord) {
			System.out.println("密码错误3次,退出系统,请取卡");
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_45155377/article/details/102736570