Day4(课堂笔记)

一.1.Continue

//用于循环语句,跳过本次循环,直接进入下次循环

一方面跳出循环,直接进入下次循环,另一方面可以加速循环

案例:

public class Demo {
   
public static void main(String[] args) {
       
//循环录入数据
        //判断输入的数据是否小于80,如果小于,则计数器不会自增
       
int num=0;//计数器
       
Scanner input=new Scanner(System.in);
       
for (int i = 0; i < 5; i++) {
            System.
out.println("请输入第"+(i+1)+"次成绩:");
           
double cj = input.nextDouble();
           
if (cj<80){
               
continue;//一方面跳出循环,直接进入下次循环,另一方面可以加速循环
           
}
            num++;
        }
        System.
out.println("大于80分的分数个数为:"+num);
    }
}

2.System.exit(-1);//代表java JVM退出

//ATM机存取款机案例:

import java.util.Scanner;



public class Demo1 {

        public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);

            System.out.println("=====欢迎使用中国银行ATM机自动存取款机=====");

            System.out.println("1.取款\t2.存款\t3.查询余额\t4.退出系统" );

            System.out.println("==========================================");

            System.out.println("请选择您需要的服务:");

            double ye = 5000.00;

            int xx = sc.nextInt();

            do {

                switch (xx){

                    case 1:

                        System.out.println("请输入您的取款金额:");

                        double qkje = sc.nextDouble();

                        if (qkje<ye){

                            ye = ye-qkje;

                            System.out.println("取款成功!您的取款金额为:"+qkje);

                        }else {

                            System.out.println("很抱歉,您的余额不足!");

                        }

                        break;

                    case 2:

                        System.out.println("请输入您的存款金额:");

                        double ckje = sc.nextDouble();

                        ye += ckje;

                        System.out.println("存款成功!您的存款金额为:"+ckje);

                        break;

                    case 3:

                        System.out.println("您的余额为:"+ye);

                        break;

                    case 4:

                        System.out.println("谢谢使用,欢迎下次使用!");

                        System.exit( -1);

                        break;

                }

                System.out.println("=====欢迎使用中国银行ATM机自动存取款机=====");

                System.out.println("1.取款\t2.存款\t3.查询余额\t4.退出系统" );

                System.out.println("==========================================");

                System.out.println("请选择您需要的服务:");

                xx = sc.nextInt();

            }while (true);

        }

    }

完善版:

import java.util.Scanner;



public class zy1 {

        public static void main(String[] args) {

            // 假设正确的账号和密码

            String zh = "123456";

            String mm= "123321";



            int cs = 3; // 次数



            Scanner scanner = new Scanner(System.in);

            System.out.println("欢迎来到中国银行!");



            while (cs > 0) {

                System.out.print("请输入账号: ");

                String zhzh = scanner.next();

                System.out.print("请输入密码: ");

                String mmmm = scanner.next();



                if (zhzh.equals(zh) && mmmm.equals(mm)) {

                    System.out.println("登录成功!");

                    break; // 登录成功,退出循环

                } else {

                   cs--;

                    System.out.println("登录失败,剩余尝试次数: " + cs);

                }

            }



            if (cs == 0) {

                System.out.println("您已经超过了最大尝试次数,账号已冻结,请联系工作人员。");

            }

            Scanner sc = new Scanner(System.in);

            System.out.println("*****欢迎使用中国银行ATM机自动存取款机*****");

            System.out.println("1.取款\t2.存款\t3.查询余额\t4.退出系统" );

            System.out.println("******************************************");

            System.out.println("请选择您需要的服务:");

            double yu = 5000.00;

            int xx = sc.nextInt();

            do {

                switch (xx){

                    case 1:

                        System.out.println("请输入您的取款金额:");

                        double qkje = sc.nextDouble();

                        if (qkje<yu){

                            yu = yu-qkje;

                            System.out.println("取款成功!您的取款金额为:"+qkje);

                        }else {

                            System.out.println("很抱歉,您的余额不足!");

                        }

                        break;

                    case 2:

                        System.out.println("请输入您的存款金额:");

                        double ckje = sc.nextDouble();

                        yu += ckje;

                        System.out.println("存款成功!您的存款金额为:"+ckje);

                        break;

                    case 3:

                        System.out.println("您的余额为:"+yu);

                        break;

                    case 4:

                        System.out.println("谢谢使用,欢迎下次使用!");

                        System.exit( -1);

                        break;

                }

                System.out.println("*****欢迎使用中国银行ATM机自动存取款机*****");

                System.out.println("1.取款\t2.存款\t3.查询余额\t4.退出系统" );

                System.out.println("******************************************");

                System.out.println("请选择您需要的服务:");

                xx = sc.nextInt();

            }while (true);

        }

    }







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值