第四章 选择结构(二)

第一题:

public static void main(String[] args) {
//         Scanner scanner = new Scanner(System.in);
//         System.out.print("请输入您的号码:");
//         int fdfds = scanner.nextInt();
//        switch (fdfds) {
//        case 1:
//            System.out.println("拨打爸爸电话中。。。");
//            break;
//        case 2:
//            System.out.println("拨打妈妈电话中。。。");
//            break;
//        case 3:
//            System.out.println("拨打爷爷电话中。。。");
//            break;
//        case 4:
//            System.out.println("拨打奶奶电话中。。。");
//            break;
//
//        default:System.out.println("您的号码有误!");
//            break;
//        }
//    }

第二题:

public static void main(String[] args) {
//        System.out.println("\n\t\t欢迎来到我行我素购物管理系统\n");
//        System.out.println("\t\t\t1.登录系统\n");
//        System.out.println("\t\t\t2.退出\n");
//        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * \n");
//        System.out.print("请选择,输入数字:");
//        Scanner scanner = new Scanner(System.in);
//        int fggggg = scanner.nextInt();
//            switch (fggggg) {
//            case 1:{
//                System.out.println("\n\t\t欢迎使用我行我素购物管理系统\n");
//                System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * \n");
//                System.out.println("\t\t\t1.客户信息管理\n");
//                System.out.println("\t\t\t2.购物结算\n");
//                System.out.println("\t\t\t3.真情回馈\n");
//                System.out.println("\t\t\t4.注销\n");
//                System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * \n");
//                System.out.println("请选择,输入数字:");
//                int fefgh = scanner.nextInt();
//                switch (fefgh) {
//                case 1:
//                    System.out.println("\n\t\t欢迎使用我行我素购物管理系统\n");
//                    System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * \n");
//                    System.out.println("\t\t\t1.客户信息管理\n");
//                    System.out.println("\t\t\t2.购物结算\n");
//                    break;
//                case 2:
//                    
//                    break;
//                case 3:
//                    
//                    break;
//                case 4:
//                    
//                    break;
//                default:
//                    break;
//                }
//                break;
//            }
//            case 2 :
//                System.out.println("谢谢您的使用!");
//                break;
//            default:
//                break;
//            }
//    }

第三题:

public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        System.out.print("请输入消费金额:");
//        int sfggfd = scanner.nextInt();
//        System.out.println("是否参加优惠换购活动?");
//        String sfggf = scanner.next();
//        int a = 2;
//        int b = 3;
//        int c = 10;
//        int d = 20;
//        if(sfggfd>50){
//            if(sfggf.equals("是")){
//                System.out.println("1:满50元,加2元换购百事可乐饮料一瓶");
//                System.out.println("2.满100元,加3元换500lm可乐一瓶");
//                System.out.println("3.满100元,加10元换购5公斤面粉");
//                System.out.println("4.满200元,加10元可换购1个苏泊尔炒菜锅");
//                System.out.println("5.满200元,加20元可换购欧莱雅爽肤水一瓶");
//                System.out.println("0.不换购");
//                System.out.print("请选择:");
//            }else if(sfggf.equals("否")){
//                System.out.println("本次消费总金额:"+sfggfd);
//            }
//        }else{
//            System.out.println("您没有资格参加优惠活动");
//        }
//        int systme = scanner.nextInt();
//        double aa =(sfggfd+a);
//        double bb =(sfggfd+b);
//        double cc =(sfggfd+c);
//        double dd =(sfggfd+d);
//         switch (systme) {
//         case 0:
//            System.out.println("本次消费总金额:"+sfggfd);
//         break;
//         case 1:
//            System.out.println("本次消费总金额:"+aa);
//            System.out.println("成功换购:百事可乐一瓶!");
//         break;
//         case 2:
//                System.out.println("本次消费总金额:"+bb);
//                System.out.println("成功换购:500ml可乐一瓶!");
//             break;
//         case 3:
//                System.out.println("本次消费总金额:"+cc);
//                System.out.println("成功换购:5公斤面粉!");
//             break;
//         case 4:
//                System.out.println("本次消费总金额:"+cc);
//                System.out.println("成功换购:苏泊尔炒菜锅一个!");
//             break;
//         case 5:
//                System.out.println("本次消费总金额:"+dd);
//                System.out.println("成功换购:欧莱雅爽肤水一瓶!");
//             break;
//         default:
//         break;
//         }
//    }

第四题:

public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("请输入星期几:");
//        int dfdgh = scanner.nextInt();
//        switch (dfdgh) {
//        case 1:
//           System.out.println("玩英雄联盟");
//            break;
//        case 2:
//               System.out.println("玩穿越火线");
//                break;
//        case 3:
//               System.out.println("学习编程");
//                break;
//        case 4:
//               System.out.println("玩QQ飞车");
//                break;
//        case 5:
//               System.out.println("玩刺激战场");
//                break;
//        case 6:
//               System.out.println("玩4399小游戏");
//                break;
//        case 7:
//               System.out.println("休息");
//                break;
//        default:System.out.println("抱歉,你输入的日期有误!");
//            break;
//        }

第五题:

public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个操作数:");
        if (scanner.hasNextInt()) {
            int fght = scanner.nextInt();
            Scanner ffg = new Scanner(System.in);
            System.out.println("请输入第二个操作数:");
            if (ffg.hasNextInt()) {
            int wce = ffg.nextInt();
            int qk =(fght*wce);
            int ggg = qk;
            System.out.println("计算结果:"+fght+"*"+wce+"="+ggg);
            }else{
                System.out.println("请输入正确的数值");
            }
        }else{
            System.out.println("请输入正确的数值");
        }
    }

}

理论总结

1.switch选择结构语法执行过程:

先计算并获得switch后面小括号里面的表达式或变量的值,然后将计算结果顺序与每个case后的常量比较,

当二者相当时,执行这个case块中的代码;当遇到break时,就跳出switch选择结构,执行switch选择结构

之后的代码。

2.switch和多重if选择结构的区别与相同:

相同:它们都是用来处理多分支条件的结构;

区别:但是switch选择结构只能用于等值条件判断的情况,多重if选择结构没有switch选择结构的限制,

特别适合某个变量处于某个连续区间时的情况。

3.break:只要满足这个条件   执行完动作  就会跳出这个选择;default 相当于 else。

4.switch选择结构可以嵌套if选择结构。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值