Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    (JAVA) why am getting this error in "if else" statement?

    import java.util.Scanner;

    public class Lab4_Ex2
    {
    public static void main(String[] args)
    {
    String input;
    int firstTest;
    int secondTest;
    int thirdTest;
    int finalGrade;


    Scanner keyboard = new Scanner(System.in);


    // Get the fisrt test grade from the user

    System.out.print("Enter the first test grade: ");
    firstTest = keyboard.nextInt();

    // Get the second test grade from the user

    System.out.print("Enter the second test grade: ");
    secondTest = keyboard.nextInt();

    // Get the third test grade from the user

    System.out.print("Enter the third test grade: ");
    thirdTest = keyboard.nextInt();




    if (firstTest < secondTest && firstTest < thirdTest)
    {
    finalGrade = secondTest + thirdTest;
    System.out.println("First Test: " + firstTest + "\nSecond Test: " + secondTest + "\nthirdTest: " + thirdTest);
    System.out.println("After dropping test 1, the final grade is " + finalGrade + ".");
    }
    else if (secondTest < firstTest && secondTest < thirdTest)
    {
    finalGrade = firstTest + thirdTest;
    System.out.println("First Test: " + firstTest + "\nSecond Test: " + secondTest + "\nthirdTest: " + thirdTest);
    System.out.println("After dropping test 2, the final grade is " + finalGrade + ".");

    }
    else if (thirdTest < firstTest && thirdTest < secondTest)
    {
    finalGrade = firstTest + secondTest;
    System.out.println("First Test: " + firstTest + "\nSecond Test: " + secondTest + "\nthirdTest: " + thirdTest);
    System.out.println("After dropping test 3, the final grade is " + finalGrade + ".");
    }

    if (finalGrade >= 90)
    System.out.println("The final letter grade is A.");

    else if(finalGrade < 90 && finalGrade >= 80)
    System.out.println("The final letter grade is B.");

    else if (finalGrade < 80 && finalGrade >= 70)
    System.out.println("The final letter grade is C.");

    else if (finalGrade < 70 && finalGrade >= 60)
    System.out.println("The final letter grade is D.");

    else if (finalGrade < 60)
    System.out.println("The final letter grade is F.");




    }
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    This is the javaSCRIPT forum.

    Your question is about JAVA.

    About the only thing the two languages have in common is the first four letters of their names.

    ***********

    When you repost this in the JAVA forum, be sure to say *WHICH* "else if" you see the error on.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •