Java uses nested loop to simulate ATM withdrawal business operation example
•
Java
This paper illustrates how Java uses nested loops to simulate ATM withdrawal business operations. Share with you for your reference, as follows:
code:
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(money%100==0&&money>0&&money<=1000){ System.out.println("您取了"+money+"元"); System.out.println("交易完成,请取卡!"); return; }else{ System.out.println("金额有误,请重新输入"); } } } } } }
For more information about Java algorithms, readers who are interested can see the topics on this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills
I hope this article will be helpful to you in Java programming.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码