0
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

Edited by Nick Evan: Fixed formatting

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

When 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

Edited by happygeek: fixed formatting

0

The error is with the line
if( robotsALive[] == false )
it says error '.class' expected

0

That 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( robotsALive == false )

ps that can be written more simply as
if ( !robotsALive )

0

I know that the code is not right I was just wondering what would make the commented psedocode work for this method?

public int deadRobots (int robotCount, boolean robotsAlive[])
{
int deadRobots = 0;

boolean robotsALive = true;

//a for loop to loop through the array
//inside the for loop
//and if statment that says if robotsALive[] == false
//increment deadrobots by 1
//return the value of deadRobots outside the for loop

}

0

Nothing. The pseudocode just has the same invalid concept of array==false
ps: I gave you the answer already in my previous post.

Edited by JamesCherrill: ps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.