weixin_57698413 2021-08-12 12:12 采纳率: 91.2%
浏览 18
已结题

应该将固定的开头放在程序的哪里

img

img

img

img

  • 写回答

1条回答 默认 最新

  • zlebhs 2021-08-12 13:53
    关注

    根据题目意思来写吧,写哪不重要

    public static void main(String[] args) {
            // 固定的开头是什么意思?是指输出价格的前缀?
            String prefix = "price = ";
            // 还是指的这个
            System.out.println("[1] apple");
            System.out.println("[2] pear");
            System.out.println("[3] orange");
            System.out.println("[4] grape");
            System.out.println("[0] exit");
    
            for (int i = 0; i < 5; i++) {
                // 或者写这里
                // System.out.println("[1] apple");
                // System.out.println("[2] pear");
                // System.out.println("[3] orange");
                // System.out.println("[4] grape");
                // System.out.println("[0] exit");
                Scanner sc = new Scanner(System.in);
                int index = sc.nextInt();
                switch (index) {
                    case 1:
                        System.out.println(prefix + "3.00");
                        continue;
                    case 2:
                        System.out.println(prefix + "2.50");
                        continue;
                    case 3:
                        System.out.println(prefix + "4.10");
                        continue;
                    case 4:
                        System.out.println(prefix + "10.20");
                        continue;
                    case 0:
                        System.out.println("exit");
                        break;
                    default:
                        System.out.println(prefix + "0.00");
                }
    
            }
            System.out.println("exit");
        }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月20日
  • 已采纳回答 8月12日
  • 创建了问题 8月12日

悬赏问题

  • ¥15 matlab使用自定义函数时一直报错输入参数过多
  • ¥15 设计一个温度闭环控制系统
  • ¥100 关于加载卡的问题有能知道这个要怎么处理吗?
  • ¥100 rtmpose姿态评估
  • ¥15 java 通过反射找路径下的类,打包后就找不到
  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,
  • ¥15 centos7系统下abinit安装时make出错
  • ¥15 hbuildex运行微信小程序报错
  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy