我已经搜索了大约一个小时,但还没有找到解决我的问题的方法。我正在尝试使用我的扫描仪变量输入稍后在我的 switch 参数中使用它,但我目前被困在第二行,因为正确的语法是为了让我的问题正常工作。这是我的java问题:
//为KW输入创建扫描器
Scanner kw = new Scanner(System.in);
double kwUsed = kw;
//Verify if KW is valid
try
{
//KW used data entry
System.out.println("Please enter KW used: ");
kwUsed = kw.nextDouble();
System.out.println("KW entry valid");
}
catch (Exception error)
{
System.out.println("Invalid entry");
System.out.println(error);
}
//Date entry will be calculated by how much KW user enters
switch (input)
{
case "2/15/13":
double quarter1 = kwUsed * 0.10;
break;
case "4/15/13":
double quarter2 = kwUsed * 0.12;
break;
case "8/15/13":
double quarter3 = kwUsed * 0.15;
break;
case "11/15/13":
double quarter4 = kwUsed * 0.15;
break;
default:
System.out.println("Invalid date");
}