以下是代码:
import java.util.*;
public class dayName {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter the number to find out what day of the week it represents:");
int number = in.nextInt();
weekNumber(number);
}
public static String weekNumber(int number)
{
String dayNumber;
switch (number)
{
case 1: dayNumber = "Monday"; break;
case 2: dayNumber = "Tuesday"; break;
case 3: dayNumber = "Wednesday"; break;
case 4: dayNumber = "Thursday"; break;
case 5: dayNumber = "Friday"; break;
case 6: dayNumber = "Saturday"; break;
case 7: dayNumber = "Sunday"; break;
default: dayNumber = ""; break;
}
return dayNumber;
}
}
我的问题是它编译得很好但是当你问它的数字时它没有返回任何东西,它应该根据你输入的数字返回日期字符串。
请记住我正在学习Java。
答案 0 :(得分:6)
weekNumber()
只返回值,但您不对其执行任何操作。
将该行更改为:
System.out.println(weekNumber(number));
答案 1 :(得分:2)
您必须将名称写入控制台:
System.out.println(weekNumber(number));
答案 2 :(得分:1)
你在哪里询问这个号码? 如果你在main方法中询问这行代码:
weekNumber(number);
不会将String分配给String变量。
在主方法中尝试这个
System.out.println(weekNumber(number));
希望这有帮助!