【发布时间】:2015-06-28 23:14:04
【问题描述】:
public class MonthName {
public static String month_name(int month) {
String result;
if (month == 1) {
result = "January";
} else if (month == 2) {
result = "February";
} else if (month == 3) {
result = "February";
} else if (month == 4) {
result = "February";
} else if (month == 5) {
result = "February";
} else if (month == 6) {
result = "February";
} else if (month == 7) {
result = "February";
} else if (month == 8) {
result = "February";
} else if (month == 9) {
result = "February";
} else if (month == 10) {
result = "February";
} else if (month == 11) {
result = "February";
} else if (month == 12) {
result = "February";
}
return result;
}
public static void main(String[] args) {
System.out.println("Month 1: " + month_name(1));
System.out.println("Month 2: " + month_name(2));
System.out.println("Month 3: " + month_name(3));
System.out.println("Month 4: " + month_name(4));
System.out.println("Month 5: " + month_name(5));
System.out.println("Month 6: " + month_name(6));
System.out.println("Month 7: " + month_name(7));
System.out.println("Month 8: " + month_name(8));
System.out.println("Month 9: " + month_name(9));
System.out.println("Month 10: " + month_name(10));
System.out.println("Month 11: " + month_name(11));
System.out.println("Month 12: " + month_name(12));
System.out.println("Month 43: " + month_name(43));
}
}
所以我已经在结果中声明了相关字符串的值,但它仍然说我的变量“结果”可能没有被初始化。
我正在尝试实现类似于this 的输出。 任何人都可以帮助我吗?谢谢!
【问题讨论】:
标签: java