gpt4 book ai didi

java - 为什么我的输入扫描仪和程序的其余部分无法工作?

转载 作者:行者123 更新时间:2023-12-01 11:21:49 25 4
gpt4 key购买 nike

有人可以帮我修复我的代码以使其正常工作吗?在控制台中它不允许我输入任何内容。有人可以在他们的计算机上测试代码并向我发送带有固定代码的评论吗?如果没有,你能告诉我我的代码有什么问题吗?

字符串是="is";

    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")){

}

最佳答案

您正在将 ScannerString 进行比较。您希望在比较输入之前将输入存储为字符串。试试这个:

...
Scanner input = new Scanner(System.in);
String yes = "yes";
String answer = input.nextLine();

if (answer.equals(yes)){
...
}

关于java - 为什么我的输入扫描仪和程序的其余部分无法工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31137691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com