有人可以帮我修改我的代码以使其正常工作。在控制台中,它不允许我键入任何内容。有人可以在他们的计算机上测试代码并用固定代码发送评论吗?如果没有,你能告诉我我的代码有问题吗?
String yes =" yes&#34 ;;
System.out.println("Do you have gym this semester?");
input.nextLine();
if (input.equals(yes)){
int Gym;
double GymGpa = 0;
System.out.println("Gym = ");
Gym= input.nextInt();
input.close();
if (Gym >100){
System.out.println("You have mistyped something");
}
if (Gym >= 94 && Gym < 101){
System.out.println("You have an A");
GymGpa = 4.0;
System.out.println(GymGpa);
}
if (Gym < 94 && Gym >=90){
System.out.println("You have an A-");
GymGpa = 3.7;
System.out.println(GymGpa);
}
if (Gym < 90 && Gym >=87){
System.out.println("You have a B+");
GymGpa = 3.3;
System.out.println(GymGpa);
}
if (Gym < 87 && Gym >=80){
System.out.println("You have a B");
GymGpa = 3.0;
System.out.println(GymGpa);
}
if (Gym < 80 && Gym >=77){
System.out.println("You have a B-");
GymGpa = 2.7;
System.out.println(GymGpa);
}
if (Gym < 77 && Gym >=73){
System.out.println("You have a C+");
GymGpa = 2.3;
System.out.println(GymGpa);
}
if (Gym < 73 && Gym >=70){
System.out.println("You have a C");
GymGpa = 2.0;
System.out.println(GymGpa);
}
if (Gym < 70 && Gym >=67){
System.out.println("You have a C-");
GymGpa = 1.7;
System.out.println(GymGpa);
}
if (Gym < 67 && Gym >=67){
System.out.println("You have a D+");
GymGpa = 1.3;
System.out.println(GymGpa);
}
if (Gym < 67 && Gym >=63){
System.out.println("You have a D");
GymGpa = 1.0;
System.out.println(GymGpa);
}
if (Gym < 63 && Gym >=60){
System.out.println("You have a D-");
GymGpa = 0.7;
System.out.println(GymGpa);
}
if (Gym < 60){
System.out.println("You have a F");
GymGpa = 0.0;
System.out.println(GymGpa);
}//End of Gym
}else if (input.equals("no")){
}
答案 0 :(得分:1)
您正在将Scanner
与String
进行比较。您希望在比较之前将输入存储为String。
试试这个:
...
Scanner input = new Scanner(System.in);
String yes = "yes";
String answer = input.nextLine();
if (answer.equals(yes)){
...
}