I have this code for an assignment. When I compile it, I get
grades.java:18: error: 'else' without 'if'
else
^
1 error
Here is the code:
public class grades
{
public static void main (String [] args)
{
int gradeone=75;
int gradetwo=80;
int testscore= ((gradeone + gradetwo)/2);
char grade;
System.out.println("\n" + "your test score is" + testscore);
if(testscore >= 90 )
grade='A';
elseif(testscore >= 80 );
grade='B';
elseif(testscore >= 70 );
grade='C';
elseif(testscore >= 65 );
grade='D';
else
grade='F';
}
}
As others have already mentioned the syntax is else if - mind the space.
Moreover, I highly recommend you stick to conventional coding style until you become more confident in your skills.
A) For now, use brace syntax when using blocks and statements. Your code will be more readable and you will be able to identify your syntax errors easier. Though technically not required, you will be challenged trying to determine local variables and method scope without braces.
B) When your uncertain about the syntax refer to the JLS for answers ...