下面是代碼:方法問題使用switch語句,返回工作不
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。
添加的System.out來顯示被傳遞到weekNumber()方法的數量。 – DwB