How to use nested loops to simulate ATM withdrawal operations in Java
Editor to share with you how Java uses nested loops to simulate ATM withdrawal business operations, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
The details are as follows:
Package com.jredu.ch03;import java.util.Scanner;public class Work4 {public static void main (String [] args) {/ / TODO Auto-generated method stub Scanner scan = new Scanner (System.in); for (int I = 1; I
< 4; i++) { System.out.print("请输入密码:"); String pwd = scan.next(); if (!pwd.equals("111111")) { //密码错误 if(i==3){ System.out.println("密码错误,请取卡"); }else{ System.out.println("密码错误,还有"+(3-i)+"次机会"); } }else{ //密码正确 while(true){ System.out.print("请输入金额:"); int money = scan.nextInt(); if(money0==0&&money>0&&money