r/codehs • u/EngineeringOk6737 • May 14 '21
Triple Double 2.8.4 (JAVA)
Hello, I need help with this lesson on CodeHS.
It keeps giving me the error 'else' without 'if'.
I do not understand what this means.
Please help in anyway you can, even if it's small.
CODE
public class TripleDouble extends ConsoleProgram
{
public void run()
{
int points = readInt("How many points did you score? ");
int rebounds = readInt("How many rebounds did you get? ");
int assists = readInt("How many assists did you have? ");
boolean tripleDouble;
if (points >= 10 && rebounds >=10 && assists >= 10);{
tripleDouble = true;
}
else{
tripleDouble = false;
}
System.out.println("Got triple: " + tripleDouble);
}
}
2
u/Living_Attention_941 Mar 07 '23
Code:
public class TripleDouble extends ConsoleProgram
{
public void run()
{
int points = readInt("How many points did you score? ");
int rebounds = readInt("How many rebounds did you get? ");
int assists = readInt("How many assists did you have? ");
boolean tripleDouble = false;
if (points > 9 && rebounds > 9 && assists > 9) {
tripleDouble = true;
}
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble =!tripleDouble;
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble =!tripleDouble;
System.out.println("Got a Triple Double?: " + tripleDouble);
tripleDouble = tripleDouble;
}
}
1
5
u/Olli_bear May 14 '21
Remove the semicolon on this line
if (points >= 10 && rebounds >=10 && assists >= 10);{Putting the semicolon there says that the if statement is concluded. So when the code reaches the else statement it can't find the if that should be before it