有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java GPA编号到GPA字母程序。不知道为什么不起作用

package gpatogradecalculator;

import java.util.Scanner;

public class GPAtoGradeCalculator {

    public static void main(String[] args) {
        // TODO code application logic here

        double GPA = 0.0;

        Scanner response = new Scanner(System.in);

        System.out.println("Please enter your GPA: ");

        GPA = response.nextDouble();

        if(GPA >= 3.5); {
            System.out.println("Your GPA is an A.");


    }   else if(3.0<=GPA && GPA<3.5); {
            System.out.println("Your GPA is a B.");


    }   else if(2.5<=GPA && GPA <3.0); {
            System.out.println("Your GPA is a C.");

    }
        if(GPA < 2.5); {
            System.out.println("You are failing.");
    }

      } // end main

} // end class

有谁能告诉我为什么这行不通吗?我甚至不知道从哪里开始修复它。上面说我的else行没有if,但是if就在它们上面


共 (3) 个答案

  1. # 1 楼答案

    不要在每个if后面加分号

  2. # 2 楼答案

    删除if(GPA >= 3.5); {和类似if语句中的分号

  3. # 3 楼答案

    删除条件语句后的;