嗨,我正在开发碰碰车游戏,但出现错误
P:\162>javac bumpercardemo.java
bumpercardemo.java:13: 错误: '.class' 预期 printGrid(bcar[], NUMCARS); ^ bumpercardemo.java:34: 错误:预期的公共静态无效 printGrid(bcar[], int NUMCARS) ^ 2 个错误
我是新程序员,从未见过这种类型的错误。
import java.util.Random;
public class bumpercardemo
{
public static void main (String args[])
{
final int NUMCARS = 16;
bumpercar bcar[] = new bumpercar[NUMCARS];
createcars(NUMCARS, bcar);
printGrid(bcar[], NUMCARS);
}
public static void createcars(int NUMCARS, bumpercar bcar[])
{
int x=0;
int y=0;
Random generator = new Random();
char symbol = 'A';
for (int i=0; i<NUMCARS; i++)
{
bcar[i] = new bumpercar(x, y, symbol);
symbol++;
x = generator.nextInt(bcar[0].getCarSymbol());
y = generator.nextInt(bcar[0].getCarSymbol());
}
}
public static void printGrid(bumpercar bcar[], int NUMCARS)
{
//nested loop
for(int j = 0; j < 16; j++)
{
System.out.printf("\n");
for(int k = 0; k<16; k++)
{
for(int l = 0; l<NUMCARS; l++)
{
if((bcar[l].getX() == k) && bcar[l].getY() == j)
System.out.printf("%s", bcar[l].getCarSymbol());
else
System.out.printf("- ");
}
}
}
}
}
我认为它与 [] 有关,但由于我传入一个数组,我不确定还能做什么。
我检查了为什么我会收到“.class”预期错误?简单的数组脚本,但我无法完全理解它与我的程序的关系。
谢谢