Sorry if this is a stupid question, im a novice
}
public void startGame() {
score = 0; crashes = 0; cars = 0;
//driver update score Callback pattern
compCars = new Car [maxCars];
//loop through the array create the individual cars
for (int i = 0; i < maxCars.length; i++) //ERROR ON THIS LINE
compCars[i] = new Car ();//random number 0-12 random number 0-3*/)
add(compCars[i],0);
}
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
maxCars is int not array, so remove .length:
for (int i = 0; i < maxCars; i++)
If you want to compare it with the number of digits do it this way:
for (int i = 0; i < Integer.toString(maxCars).length(); i++)
Edit:
or if you mean the array:
for (int i = 0; i < compCars.length; i++)
wait a minute!
why have you kept this as condition in loop expression
maxCars.length
maxCars is integer so you should be making mistake if you call
maxcars.length
you should have
Car.length if you want to traverse through array.
Regards
Neeraj yadav