boolean robotsAlive[];
int robotCount;
public int deadRobots (int robotCount, boolean robotsAlive[])
{
int deadRobots = 0;
boolean robotsALive = true;
for( int i = 1; i > robotCount; i++ )//a for loop to loop through the array
{
//inside the for loop
if( robotsALive[] == false ) //and if statment that says if robotsALive[] == false
++deadRobots; //increment deadrobots by 1
}
//return the value of deadRobots outside the for loop
return deadRobots;
}//end of deadRobots method
KWhite
0
Newbie Poster
Recommended Answers
Jump to PostWhen you get an error always post the complete message, including the line number where the error was found.
And post your code in CODE tags
Jump to PostThat looks like an attempt to test if an array is false, which makes no sense because the array may contain some true and some false values.
Looking at the loop around that statement, I guess you meant to test just the one element of the array, as in
if( …
All 5 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
KWhite
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
KWhite
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.