[Solved] Java program. How do I loop my “isLucky” method through my array? Also, how do I print my results correctly in the main method?


Your compiler error, 'else' without 'if' is because you have something like this:

if(isOkay)
   doSomething();
   andThenDoSomethingElse();
else
   doAnotherThing();
   andEvenSomethingElse();

And you must put each block in curly braces, like this:

if(isOkay)  {
   doSomething();
   andThenDoSomethingElse();
}  else  {
   doAnotherThing();
   andEvenSomethingElse();
}

I strongly recommend using curly braces in all ifs (and whiles and fors and everything else), even when there’s only a single statement.

More information can be found at this question: Else without if

2

solved Java program. How do I loop my “isLucky” method through my array? Also, how do I print my results correctly in the main method?