I have posted the solution for Chapter 8 exercise two, of Java Programming, Joyc
ID: 3910946 • Letter: I
Question
I have posted the solution for Chapter 8 exercise two, of Java Programming, Joyce Farrell 8th Editionafter several hours of my program not working and it keeps telling me I have an error that cannot find or load main class. I copied the solution exactly, after several days of my not working. It saids, " DistanceFromAverage.java:22: error: 'else' without 'if'
else
^
1 error
Error: Could not find or load main class DistanceFromAverage
" I have a test and another assignment and have spent way too much time on this one error. can you help?
Explanation / Answer
The first error " DistanceFromAverage.java:22: error: 'else' without 'if'
It is because, you have provided the else block without the if block. In the if-else condition, you first need to mention the if condition, then the end if condition ( if any ) and at the last mention else condition.
So, the structure is
if( condition )
{
}
else if( condition )
{
}
else
{
}
The second error Error: Could not find or load main class DistanceFromAverage
It may be bacause the name of the class is not DistanceFromAverage. There could be a spelling mistake or the class name is something else.