Mor. 四楼的火车! 2021-10-12 14:46 采纳率: 100%
浏览 88
已结题

Java中case2中如何获取case1中输入的变量的值并实现加一操作

Java中case2中如何获取case1中输入的变量的值并实现加一操作

        switch (line) {
            case "M":
                System.out.println("显示指定的年月份日历");

                System.out.print("Enter full year (e.g., 2001): ");
               int year = input.nextInt();
                // Prompt the user to enter month
                System.out.print("Enter month in number between 1 and 12: ");
                int month = input.nextInt();

// input.close();
// Print calendar for the month of the year
printMonth(year, month);

            case "P":
                System.out.println("显示前一月份日历");




                printMonth(year, getMonthName(month +1));

img

  • 写回答

4条回答 默认 最新

  • CSDN专家-sinJack 2021-10-12 15:24
    关注
    static int year=0,month=0;
    switch (line) {
       case "M":
         System.out.println("显示指定的年月份日历");
         System.out.print("Enter full year (e.g., 2001): ");
         year = input.nextInt();     
         System.out.print("Enter month in number between 1 and 12: ");
         month = input.nextInt();
         printMonth(year, month);
       case "P":
        System.out.println("显示前一月份日历");
        printMonth(year, getMonthName(month +1));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'