...

View Full Version : (JAVA) why am getting this error in "if else" statement?



sabi
10-12-2011, 09:43 PM
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.");




}
}

Old Pedant
10-12-2011, 10:14 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum