我们的老师教我们关于if-else
语句的知识,他正在教我们如何使用switch
语句作为替代方案,if-else
所以我在编码时遇到了这个无法访问的语句错误。我不知道我应该如何调试,因为我刚刚将我的 Java 从 6 更新到 8,而且我真的不知道我的代码有什么问题。
import java.io.*;
import java.util.Scanner;
class Switch
{
public static void main(String[] args)
{
Scanner k = new Scanner(System.in);
System.out.println("Whats your name?");
String name = k.nextLine();
System.out.println("Do you want to compute your grades?");
String yesNo = k.nextLine();
switch(yesNo)
{
case "yes":
System.out.println("Input your attendance grade(10%)\n");
int attendance = k.nextInt();
System.out.println("Input your participation grade (10%)\n");
int participation = k.nextInt();
System.out.println("Input your quiz grade (10%)\n");
int quiz = k.nextInt();
System.out.println("Input your exam grade(40%)\n");
int exam = k.nextInt();
System.out.println("Input your lab grade (20%)\n");
int lab = k.nextInt();
double point10 = 0.10;
double point20 = 0.20;
double point40 = 0.40;
double attendanceC = attendance*point10;
double participationC = participation*point10;
double quizC = quiz*point20;
double examC = exam*point40;
double labC = lab*point20;
double yourGradeD = attendanceC+participationC+quizC+examC+labC;
int yourGrade = (int)yourGradeD;
break;
default:
System.out.println("Thank you "+name);
break;
switch(yourGrade)
{
case 99|98|97|96|95|94|93|92|91|90:
System.out.println("testing");
break;
}
}
}
}