我对编程非常陌生,并且正在处理一个实践do/while循环和switch语句的赋值。我已经写出了一个列出博物馆时间的程序并编译,但我似乎无法让它正常工作。它只是抛出:程序在我的Do/While循环中抛出异常
import java.util.Scanner;
public class MuseumHours {
public static void main (String[] args) {
Scanner stdIn = new Scanner(System.in);
//variables
String day;
boolean holiday = true;
String userContinue;
String monday = "Closed";
//end variables
//begin program
do {
System.out.println("Hello! Thank you for visiting the museum's website. For what day would you like to view our hours of operation?");
day = stdIn.nextLine();
System.out.println("Is today a holiday?");
holiday = stdIn.nextBoolean();
switch (day) {
case "Monday":
System.out.println(monday);
case "Tuesday":
if (holiday !=true) {
System.out.println("The museum is open from 12:00 to 4:00.");
} else {
System.out.println("The museum is open from 1:00 to 3:00.");
}
break;
case "Wednesday":
if (holiday !=true) {
System.out.println("The museum is open from 12:00 to 4:00.");
} else {
System.out.println("The museum is open from 1:00 to 3:00.");
}
break;
case "Thursday":
if (holiday != true) {
System.out.println("Today the museum opens from 10:00 to 5:00.");
} else {
System.out.println("Today the museum opens from 11:00 to 4:00.");
}
break;
case "Friday":
if (holiday != true) {
System.out.println("Today the museum opens from 10:00 to 5:00.");
} else {
System.out.println("Today the museum opens from 11:00 to 4:00.");
}
break;
case "Saturday":
if (holiday != true) {
System.out.println("Today the museum is open from 9:00 to 6:00.");
} else {
System.out.println("Today the museum is open from 10:00 to 5:00.");
}
break;
case "Sunday":
if (holiday != true) {
System.out.println("Today the museum is open from 9:00 to 6:00.");
} else {
System.out.println("Today the museum is open from 10:00 to 5:00.");
}
break;
default:
System.out.println("Invalid day.");
}
System.out.println("Would you like to run the program again? Enter Y for yes, or N for no.");
userContinue = stdIn.nextLine();
} while (userContinue.equals("Y"));
}
}
_它只是抛出:_ ..你有什么异常? –
抛出什么异常以及哪些输入? –
周一 –