mardi 13 décembre 2016

Else If Statements

Hi I am new to Java programming and programming/coding in general and I was trying to make a program that can basically tell you your grade from two point values. Actually it is from a website i'm sure most of you know of, it is where I am learning to write Java. http://ift.tt/1TYoEMG It is exercise 18 - grades and points. My problem is with the if else statements. On the website above that exercise it shows using if else statements below one another/more than once in a row, but when I try and do that it gives me an error and tells me to remove the else. Here is the code I have written.

import java.util.Scanner;

public class failedorpass {
    public static void main (String args[]) {
        Scanner reader = new Scanner(System.in);

    int p1 = 0;
    int p2 = 29;

    int p3 = 30;
    int p4 = 34;

    int p5 = 35;
    int p6 = 39;

    int p7 = 40;
    int p8 = 44;

    int p9 = 48;
    int p10 = 52;

    int p11 = 56;
    int p12 = 60;

    System.out.print("Enter the points (0 - 60): ");
    int num1 = Integer.parseInt(reader.nextLine());

    if (num1 > p1) {
        System.out.println("Grade: F ");
    } else if (num1 > p2); {
        System.out.println("Grade: 1");

    } else if (num1 > p3); {
        System.out.println("Grade: 1");
    } else if (num1 < p4); {
        System.out.println("Grade: 1");
    }


}

}

Any help would be very much appreciated. Sorry if I worded the question wrong or made a stupid question, or even a duplicate question, I looked at the similar questions and questions that may have my answer and none of them did. The weirdest part is that I used if else statements in the past while using them consecutively and had no error. I've been looking for an hour for an error in my code and couldn't find one so i resorted to asking on stackoverflow. Anyways again, any help would be amazing. Thanks.

Aucun commentaire:

Enregistrer un commentaire