import java.util.*;
public class assigment4number3
{
public static void main (String [] args)
{
int mon, tues, wed, thurs, fri;
mon=1; tues=2; wed=3;thurs=4;fri=5;
Scanner day = new Scanner(System.in);
System.out.println("Enter Day of week: mon, tues, weds, thurs, fri, sat, sun");
String week= day.next();
switch (week) {
case 1:
System.out.println(" Discrete Math");
System.out.println("Philosophy");
System.out.println("Calculus");
break;
case 2:
System.out.println("Modern World");
System.out.println("Java Programming");
break;
case 3:
System.out.println(" Discrete Math");
System.out.println("Philosophy");
System.out.println("Calculus");
break;
case 4:
System.out.println("Modern World");
System.out.println("Java Programming");
break;
case 5:
System.out.println("Discreet Math");
System.out.println("Philosophy");
break;
default:
System.out.println("Its the weekend");
break;
}
}
}
我正在尝试在我的交换机中使用输入我正在编写一个代码,我可以在一周中计算一天,我的日程安排应该弹出,但是我在交换机中使用输入时遇到了问题
你所有的case
标签都是int
类型。将它们改为String
或switch
。喜欢,
int
要么
int week = day.nextInt();
如果您的意思是使用值switch (week) {
case "1":
System.out.println(" Discrete Math");
System.out.println("Philosophy");
System.out.println("Calculus");
break;
case "2":
System.out.println("Modern World");
System.out.println("Java Programming");
break;
case "3":
System.out.println(" Discrete Math");
System.out.println("Philosophy");
System.out.println("Calculus");
break;
case "4":
System.out.println("Modern World");
System.out.println("Java Programming");
break;
case "5":
System.out.println("Discreet Math");
System.out.println("Philosophy");
break;
default:
System.out.println("Its the weekend");
break;
}
- mon
而不是数字,您可以将它们用于fri
标签。喜欢,
case