gpt4 book ai didi

Java case 语句未初始化变量

转载 作者:行者123 更新时间:2023-12-02 11:10:52 24 4
gpt4 key购买 nike

如果我从 JOptionPane 中注释掉月份,我就可以让我的代码正常工作。似乎 switch case 没有公开设置变量(如果这是有道理的)。这是我的代码。

    String[] sDateIn = jTextField1.getText().split("/");
int mDate = Integer.parseInt(sDateIn[0]);
int dDate = Integer.parseInt(sDateIn[1]);
int yDate = Integer.parseInt(sDateIn[2]);
String month;
switch (mDate) {
case 1:
month = "Jan";
break;
case 2:
month = "Feb";
break;
case 3:
month = "Mar";
break;
case 4:
month = "Apr";
break;
case 5:
month = "May";
break;
case 6:
month = "Jun";
break;
case 7:
month = "Jul";
break;
case 8:
month = "Aug";
break;
case 9:
month = "Sep";
break;
case 10:
month = "Oct";
break;
case 11:
month = "Nov";
break;
default:
month = "Dec";
break;
}
//display output
JOptionPane.showMessageDialog(this, "The converted date is " + Month + " " + dDate + ", " + yDate);

最佳答案

似乎您要附加月份而不是月份

JOptionPane.showMessageDialog(this, "The converted date is " + month /*Month to month*/ + " " + dDate + ", " + yDate);

关于Java case 语句未初始化变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50634385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com