import java.util.*;
創(chuàng)新互聯(lián)公司是一家以網(wǎng)絡技術(shù)公司,為中小企業(yè)提供網(wǎng)站維護、網(wǎng)站設(shè)計、網(wǎng)站制作、網(wǎng)站備案、服務器租用、國際域名空間、軟件開發(fā)、小程序定制開發(fā)等企業(yè)互聯(lián)網(wǎng)相關(guān)業(yè)務,是一家有著豐富的互聯(lián)網(wǎng)運營推廣經(jīng)驗的科技公司,有著多年的網(wǎng)站建站經(jīng)驗,致力于幫助中小企業(yè)在互聯(lián)網(wǎng)讓打出自已的品牌和口碑,讓企業(yè)在互聯(lián)網(wǎng)上打開一個面向全國乃至全球的業(yè)務窗口:建站電話聯(lián)系:028-86922220
public class ATM {
static int people=123456;
static int mima=123456;
static int yue=10000;
static Scanner in=null;
public ATM(int people,int mima){
this.mima=mima;
}
public static void main(String[] args) {
chongxindenglu();
int count=1;
while(count!=0){
System.out.println("1、查詢余額");
System.out.println("2、取款");
System.out.println("3、存款");
System.out.println("4、修改密碼");
System.out.println("5、重新登錄");
count=in.nextInt();
switch(count){
case 1: System.out.println(10000); System.out.println(); break;
case 2: quKuan(); break;
case 3: cunKuan(); break;
case 4: xiugai(); break;
case 5: chongxindenglu();
}
}
}
public static void quKuan(){
System.out.println("請輸入取款金額:");
int qukuanjine=in.nextInt();
if(qukuanjine5000){
System.out.println("取款金額不能大于5000"+"\n");
}else{
if(qukuanjine%100!=0){
System.out.println("取款金額必須為100的整數(shù)倍"+"\n");
}else{
yue=yue-qukuanjine;
System.out.println("您取出了"+qukuanjine+"元,您現(xiàn)在的余額為:"+yue+"元"+"\n");
}
}
}
public static void cunKuan(){
System.out.println("請輸入存款金額");
int cunkuanjine=in.nextInt();
if(cunkuanjine0){
System.out.println("存款金額不能小于0");
}else{
yue=yue+cunkuanjine;
System.out.println("您已成功存入:"+cunkuanjine+"元,您現(xiàn)在總余額為:"+yue+"元"+"\n");
}
}
public static void xiugai(){
System.out.println("請輸入您的密碼:");
int mima1=in.nextInt();
if(mima1==mima){
System.out.println("請輸入新密碼:");
mima=in.nextInt();
System.out.println("您的密碼已修改為:"+mima+"\n");
}else{
System.out.println("密碼輸入錯誤:"+"\n");
}
}
public static void chongxindenglu(){
in=new Scanner(System.in);
System.out.println("請輸入登錄帳號:");
int denglupeople=in.nextInt();
System.out.println("請輸入登錄密碼:");
int denglumima=in.nextInt();
if(denglupeople==people denglumima==mima)
System.out.println("帳號登錄成功"+"\n");
else
System.out.println("密碼輸入錯誤,登錄失敗"+"\n");
}
}
package arraylist;
import java.util.Scanner;
public class AtmDemo
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Boolean flag = true;
int times = 0;
while(flag){
times++;
if(times == 4){
System.out.println("密碼錯誤,請取卡");
break;
}
System.out.println("請輸入你的密碼");
String password = sc.next();
if(password.equals("111111")){
Boolean moneyflag = true;
while(moneyflag){
System.out.println("請輸入金額");
int number = sc.nextInt();
if(number = 0 number = 1000 number % 100 == 0){
System.out.println("用戶取了" + number + "元。交易完成");
moneyflag = false;
}else{
System.out.println("請重新輸入金額");
}
}
break;
}else{
continue;
}
}
}
}
修改如下:
package atm;
import java.util.Scanner;
public class atmm {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("請輸入登錄密碼:");
Scanner scan=new Scanner(System.in);
int screct=scan.nextInt();
scan.close();
}
}
然后,根據(jù)screct判斷密碼是否正確。