0
我看過所有其他類似的線程在這裏,我仍然無法弄清楚爲什麼我的程序只打印A或A-無論如何。請解釋我做錯了什麼以及如何改變它。謝謝!爲什麼我的if/else if語句不起作用?
import static java.lang.System.*;
import java.util.Scanner;
public class Grading
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int grade;
out.println("Please enter your grade to be evaluated: ");
grade = sc.nextInt();
if(grade >= 93)
out.println("A");
else if(grade >= 90 && grade <= 92)
out.println("A-");
else if(grade >= 87 && grade <= 89)
out.println("B+");
else if(grade >= 83 && grade <= 86)
out.println("B");
else if(grade >= 80 && grade <= 82)
out.println("B-");
else if(grade >= 77 && grade <= 79)
out.println("C+");
else if(grade > =73 && grade <= 76)
out.println("C");
else if(grade >= 70 && grade <= 72)
out.println("C-");
else if(grade >= 67 && grade <= 69)
out.println("D+");
else if(grade >= 63 && grade <= 66)
out.println("D");
else if(grade >= 60 && grade <= 62)
out.println("D-");
else if(grade < 60)
out.println("F");
}
}
您的代碼對我的作品固定'別人後,如果(等級> = 73'到'否則,如果(等級> = 73'。 – 2014-11-02 00:40:49
小的修正爲C級條件:在'='sign'之前的空格if'(grade> = 73 && grade <= 76)'。除此之外,它對我有用 – 2014-11-02 00:41:04
在'> ='上有一個空格,如果(grade> = 73 && grade <= 76)',否則應該沒問題 – juh 2014-11-02 00:41:38